Hi,

The following code was giving me a 9997 error.

Public Class Main

  Public Structure Foo
    Public T As Integer
  End Structure

  Public Shared Sub Main()
    Dim b(,) As Boolean = { {True,False}, {False,False}}
    System.Console.Out.WriteLine(b(0,1).ToString())

    Dim f(2, 2) As Foo
    f(1,2).T = 5

    System.Console.WriteLine(f(1,2).T.ToString())
  End Sub

End Class

I looked at the IL produced by gmcs for equivalent C# code and found gmcs was using a virtual call to the Address method. The attached patch fixes the problem for me.

Thanks,
John
Index: vbnc/vbnc/source/Expressions/GetRefExpression.vb
===================================================================
--- vbnc/vbnc/source/Expressions/GetRefExpression.vb	(revision 154989)
+++ vbnc/vbnc/source/Expressions/GetRefExpression.vb	(working copy)
@@ -118,15 +118,8 @@
                             'Emitter.EmitStoreElement(Info, elementtype, arrtype)
                         End If
                     Else
-                        Return Compiler.Report.ShowMessage(Messages.VBNC99997, Parent.Location)
-                        'Dim method As MethodInfo = ArrayElementInitializer.GetSetMethod(arrtype)
-
-                        'If isnonprimitivevaluetype Then
-                        '    Helper.NotImplemented()
-                        'Else
-                        '    result = Info.RHSExpression.Classification.GenerateCode(rInfo) AndAlso result
-                        '    Emitter.EmitCallVirt(Info, method)
-                        'End If
+                        Dim method As MethodInfo = ArrayElementInitializer.GetAddressMethod(Compiler, arrtype)
+                        Emitter.EmitCallVirt(Info, method)
                     End If
                 ElseIf varC.Expression IsNot Nothing Then
                     If TypeOf varC.Expression Is MeExpression Then
Index: vbnc/vbnc/source/Members/ArrayElementInitializer.vb
===================================================================
--- vbnc/vbnc/source/Members/ArrayElementInitializer.vb	(revision 154989)
+++ vbnc/vbnc/source/Members/ArrayElementInitializer.vb	(working copy)
@@ -215,6 +215,23 @@
         Return result
     End Function
 
+    Shared Function GetAddressMethod(ByVal Compiler As Compiler, ByVal ArrayType As Type) As MethodInfo
+        Dim result As MethodInfo
+        Dim elementType As Type = ArrayType.GetElementType
+        Dim ranks As Integer = ArrayType.GetArrayRank
+        Dim methodtypes As Type() = Helper.CreateArray(Of Type)(Compiler.TypeCache.System_Int32, ranks)
+
+        If Compiler.Assembly.IsDefinedHere(ArrayType) OrElse Compiler.Assembly.IsDefinedHere(elementType) Then
+            ArrayType = Helper.GetTypeOrTypeBuilder(ArrayType)
+            elementType = Helper.GetTypeOrTypeBuilder(elementType)
+            result = Compiler.ModuleBuilder.GetArrayMethod(ArrayType, "Address", CallingConventions.HasThis Or CallingConventions.Standard, elementType, methodtypes)
+        Else
+            result = ArrayType.GetMethod("Address", BindingFlags.ExactBinding Or BindingFlags.Instance Or BindingFlags.Public Or BindingFlags.DeclaredOnly, Nothing, methodtypes, Nothing)
+        End If
+
+        Return result
+    End Function
+
     Private Function GetRegularInitializer(ByVal indices As Generic.List(Of Integer)) As Expression
         Dim ai As ArrayElementInitializer = Me
         Dim result As Expression
_______________________________________________
Mono-vb mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-vb

Reply via email to