Author: motym
Date: 2007-04-01 09:35:56 -0400 (Sun, 01 Apr 2007)
New Revision: 75260

Modified:
   
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/LateBinder.vb
   
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/LateBinding.vb
   
trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.CompilerServices/LateBindingTests6.vb
Log:
bug fix (see added unitests LateBind_IndexOfReturnObjectFromProperty1/2)

Modified: 
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/LateBinder.vb
===================================================================
--- 
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/LateBinder.vb
       2007-04-01 13:32:57 UTC (rev 75259)
+++ 
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/LateBinder.vb
       2007-04-01 13:35:56 UTC (rev 75260)
@@ -37,6 +37,26 @@
     Friend Class LateBinder
         Inherits Binder
 
+        Private _wasIncompleteInvocation As Boolean
+        Private _invokeNext As MethodInfo
+        Private _invokeNextArgs() As Object
+
+        Public ReadOnly Property WasIncompleteInvocation() As Boolean
+            Get
+                Return _wasIncompleteInvocation
+            End Get
+        End Property
+        Public ReadOnly Property InvokeNext() As MethodInfo
+            Get
+                Return _invokeNext
+            End Get
+        End Property
+        Public ReadOnly Property InvokeNextArgs() As Object()
+            Get
+                Return _invokeNextArgs
+            End Get
+        End Property
+        
         Private Enum TypeConversion
             NotConvertible
             Equal
@@ -92,7 +112,6 @@
             If nameMatches Is Nothing Then
                 Throw New MissingMemberException
             End If
-
             Dim potentialMatches() As MethodBase = FilterMethods(nameMatches, 
args, names)
 
             If potentialMatches Is Nothing Then
@@ -161,7 +180,7 @@
         End Function
 
         Public Overrides Sub ReorderArgumentArray(ByRef args() As Object, 
ByVal state As Object)
-            Dim bstate As bstate = CType(state, bstate)
+            Dim bstate As BState = CType(state, BState)
             Dim mapping() As Integer = bstate.mapping
             Dim parameters() As ParameterInfo = bstate.parameters
             Dim clone() As Object = CType(args.Clone(), Object())
@@ -796,7 +815,31 @@
             Return match
         End Function
 
+        Private Function IsGetterThatReturnObjectWithIndexer(ByVal method As 
MethodBase, ByRef args() As Object) As Boolean
+            If (method.Name.StartsWith("get_")) Then
+                Dim minfo As MethodInfo = CType(method, MethodInfo)
+                Dim retType As Type = minfo.ReturnType
+                If (retType.IsArray) Then
+                    _invokeNext = retType.GetMethod("get_Item")
+                    _invokeNextArgs = args
+                    _wasIncompleteInvocation = True
+                    args = Nothing
+                    Return True
+                End If
 
+                Dim newMethod As MethodInfo = retType.GetMethod("get_Blubber")
+                If (newMethod IsNot Nothing) Then
+                    _invokeNext = newMethod
+                    _invokeNextArgs = args
+                    _wasIncompleteInvocation = True
+                    args = Nothing
+                    Return True
+                End If
+            End If
+            Return False
+        End Function
+
+
         Private Function FilterMethods(ByVal methods() As MethodBase, ByRef 
args() As Object, ByVal names() As String) As MethodBase()
             Dim filteredMethods(methods.Length) As MethodBase
             Dim methodsCount As Integer = 0
@@ -816,7 +859,13 @@
                         If previous = TypeConversion.Equal Then
                             Exit For
                         End If
+                    ElseIf (IsGetterThatReturnObjectWithIndexer(methods(i), 
args)) Then
+                        previous = TypeConversion.Equal
+                        filteredMethods(methodsCount) = methods(i)
+                        methodsCount += 1
+                        Exit For
                     End If
+
                 Else
                     current = CompareSignature(args, parameters, names)
 

Modified: 
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/LateBinding.vb
===================================================================
--- 
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/LateBinding.vb
      2007-04-01 13:32:57 UTC (rev 75259)
+++ 
trunk/mono-basic/vbruntime/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/LateBinding.vb
      2007-04-01 13:35:56 UTC (rev 75260)
@@ -136,8 +136,12 @@
                                         BindingFlags.Static
 
             Try
-                Dim result As Object = realType.InvokeMember(name, flags, 
LBinder, o, args, Nothing, CultureInfo.CurrentCulture, paramnames)
+                Dim lb As LateBinder = New LateBinder
+                Dim result As Object = realType.InvokeMember(name, flags, lb, 
o, args, Nothing, CultureInfo.CurrentCulture, paramnames)
 
+                If (lb.WasIncompleteInvocation) Then
+                    result = lb.InvokeNext.Invoke(result, lb.InvokeNextArgs)
+                End If
                 Return result
             Catch e As MissingMethodException
                 'FIXME: should the InvokeMember always call a binder instead 
of throwing an exceptions

Modified: 
trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.CompilerServices/LateBindingTests6.vb
===================================================================
--- 
trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.CompilerServices/LateBindingTests6.vb
 2007-04-01 13:32:57 UTC (rev 75259)
+++ 
trunk/mono-basic/vbruntime/Test/Microsoft.VisualBasic.CompilerServices/LateBindingTests6.vb
 2007-04-01 13:35:56 UTC (rev 75260)
@@ -278,7 +278,50 @@
         End Sub
     End Class
 
+
     <Test()> _
+    Public Sub LateBind_IndexOfReturnObjectFromProperty1()
+        Dim o As Object
+        Dim res As Object
+        o = New A
+        res = o.dodo(0)
+        Assert.AreEqual("1", res)
+    End Sub
+
+    <Test()> _
+    Public Sub LateBind_IndexOfReturnObjectFromProperty2()
+        Dim o As Object
+        Dim res As Object
+        o = New B
+        res = o.dodo(0)
+        Assert.AreEqual("3", res)
+    End Sub
+
+    Public Class A
+        Public ReadOnly Property dodo() As Object()
+            Get
+                Return New Object() {"1", "2"}
+            End Get
+        End Property
+    End Class
+
+    Public Class B
+        Public ReadOnly Property dodo() As C
+            Get
+                Return New C
+            End Get
+        End Property
+    End Class
+
+    Public Class C
+        Default Public ReadOnly Property Blubber(ByVal i As Integer) As Object
+            Get
+                Return "3"
+            End Get
+        End Property
+    End Class
+
+    <Test()> _
     Public Sub LateBind_WithStatementA()
         Dim a As Object = New C300
         Dim bRes1 As Boolean = False

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to