Skip to content

Commit 9d9e6c0

Browse files
committed
Debugged and fixed several failing tests.
1 parent 0aa3fee commit 9d9e6c0

File tree

9 files changed

+187
-151
lines changed

9 files changed

+187
-151
lines changed

Community.VisualBasic.Tests/Community/VisualBasic/FileIO/FileSystemTests.vb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -717,15 +717,14 @@ Namespace Global.Community.VisualBasic.FileIO.Tests
717717

718718
<Fact>
719719
Public Sub MoveFile_SourceFileName_DestinationFileName_OverwriteTrue()
720-
Dim SourceFileNameWithPath As String = CreateTestFile(SourceData, TestFileName:=GetTestFileName())
721-
Dim DestinationFileNameWithPath As String = IO.Path.Combine(TestDirectory, "NewName")
720+
Dim SourceFileNameWithPath = CreateTestFile(SourceData, TestFileName:=GetTestFileName())
721+
Dim DestinationFileNameWithPath = IO.Path.Combine(TestDirectory, "NewName")
722722
FileIO.FileSystem.MoveFile(SourceFileNameWithPath, DestinationFileNameWithPath, overwrite:=True)
723723
Assert.[False](IO.File.Exists(SourceFileNameWithPath))
724724
Assert.[True](IO.File.Exists(DestinationFileNameWithPath))
725725
Assert.[True](HasExpectedData(DestinationFileNameWithPath, SourceData))
726-
' TODO: Check, VB does not directly support MemberAccess off a Conditional If Expression
727-
Dim tempVar1 = New IO.FileInfo(SourceFileNameWithPath)
728-
CreateTestFile(DestData, PathFromBase:=Nothing, TestFileName:=tempVar1.Name)
726+
'CreateTestFile(DestData, PathFromBase: null, TestFileName: (new System.IO.FileInfo(SourceFileNameWithPath)).Name);
727+
CreateTestFile(DestData, (New IO.FileInfo(SourceFileNameWithPath)).Name, Nothing)
729728
FileIO.FileSystem.MoveFile(sourceFileName:=DestinationFileNameWithPath, destinationFileName:=SourceFileNameWithPath, overwrite:=True)
730729
Assert.[True](IO.File.Exists(SourceFileNameWithPath))
731730
Assert.[False](IO.File.Exists(DestinationFileNameWithPath))

Community.VisualBasic.Tests/CompilerServices/VersionedTests.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Namespace Global.Community.VisualBasic.Tests
1919
Public Sub CallByName(instance As Object, methodName As String, useCallType As CallType, args As Object(), getResult As Func(Of Object, Object), expected As Object)
2020
Assert.Equal(If(getResult Is Nothing, expected, Nothing), Versioned.CallByName(instance, methodName, useCallType, args))
2121
If getResult IsNot Nothing Then
22-
Assert.Equal(expected, getResult(instance)())
22+
Assert.Equal(expected, getResult(instance))
2323
End If
2424
End Sub
2525

Community.VisualBasic.Tests/LateBindingTests.vb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Namespace Global.Community.VisualBasic.CompilerServices.Tests
1717
<MemberData(NameOf(LateCall_TestData))>
1818
Public Sub LateCall(obj As Object, objType As Type, name As String, args As Object(), paramNames As String(), copyBack As Boolean(), getResult As Func(Of Object, Object), expected As Object)
1919
LateBinding.LateCall(obj, objType, name, args, paramNames, copyBack)
20-
Assert.Equal(expected, getResult(obj)())
20+
Assert.Equal(expected, getResult(obj))
2121
End Sub
2222

2323
<Theory>
@@ -30,7 +30,7 @@ Namespace Global.Community.VisualBasic.CompilerServices.Tests
3030
<MemberData(NameOf(LateSet_TestData))>
3131
Public Sub LateSet(obj As Object, objType As Type, name As String, args As Object(), paramNames As String(), getResult As Func(Of Object, Object), expected As Object)
3232
LateBinding.LateSet(obj, objType, name, args, paramNames)
33-
Assert.Equal(expected, getResult(obj)())
33+
Assert.Equal(expected, getResult(obj))
3434
End Sub
3535

3636
<Theory>
@@ -64,7 +64,7 @@ Namespace Global.Community.VisualBasic.CompilerServices.Tests
6464
<MemberData(NameOf(LateIndexSet_TestData))>
6565
Public Sub LateIndexSet(obj As Object, args As Object(), paramNames As String(), getResult As Func(Of Object, Object), expected As Object)
6666
LateBinding.LateIndexSet(obj, args, paramNames)
67-
Assert.Equal(expected, getResult(obj)())
67+
Assert.Equal(expected, getResult(obj))
6868
End Sub
6969

7070
<Theory>
@@ -238,14 +238,23 @@ Namespace Global.Community.VisualBasic.CompilerServices.Tests
238238

239239
Private Structure InstanceStruct
240240

241-
Public Value As Integer
241+
Private m_value As Integer
242+
243+
Public Property Value As Integer
244+
Get
245+
Return m_value
246+
End Get
247+
Set(value1 As Integer)
248+
m_value = value1
249+
End Set
250+
End Property
242251

243252
Public Property P As Integer
244253
Get
245254
Return Value
246255
End Get
247-
Set(value As Integer)
248-
Me.Value = value
256+
Set(value1 As Integer)
257+
Value = value1
249258
End Set
250259
End Property
251260

@@ -269,8 +278,8 @@ Namespace Global.Community.VisualBasic.CompilerServices.Tests
269278
Get
270279
Return CInt(Fix(x)) + CInt(Fix(y))
271280
End Get
272-
Set(Value As Integer)
273-
Me.Value = CInt(Fix(x)) + CInt(Fix(y)) + Value
281+
Set(value1 As Integer)
282+
Value = CInt(Fix(x)) + CInt(Fix(y)) + value1
274283
End Set
275284
End Property
276285

Community.VisualBasic/Community.VisualBasic/CompilerServices/LateBinding.vb

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -680,28 +680,34 @@ UseCallType As CallType)
680680
End Function
681681

682682
<DebuggerHiddenAttribute(), DebuggerStepThroughAttribute()>
683-
Public Shared Sub LateIndexSetComplex(o As Object, args() As Object, paramnames() As String,
684-
OptimisticSet As Boolean, RValueBase As Boolean)
683+
Public Shared Sub LateIndexSetComplex(o As Object,
684+
args() As Object,
685+
paramnames() As String,
686+
OptimisticSet As Boolean,
687+
RValueBase As Boolean)
685688

686689
Try
690+
687691
LateIndexSet(o, args, paramnames)
688692

689693
If RValueBase AndAlso o.GetType().IsValueType Then
690694
Throw New Exception(SR.Format(SR.RValueBaseForValueType, o.GetType().Name, o.GetType().Name))
691695
End If
696+
692697
Catch ex As System.MissingMemberException When OptimisticSet = True
693698
'A missing member exception means it has no Set member. Silently handle the exception.
694699
End Try
700+
695701
End Sub
696702

697-
<DebuggerHiddenAttribute(), DebuggerStepThroughAttribute()>
703+
'<DebuggerHiddenAttribute(), DebuggerStepThroughAttribute()>
698704
Public Shared Sub LateIndexSet(o As Object, args() As Object, paramnames() As String)
699705

700706
Dim objType As Type
701707
Dim DefaultName As String = Nothing
702708

703709
If o Is Nothing Then
704-
Throw VbMakeException(vbErrors.ObjNotSet)
710+
Throw VbMakeException(VbErrors.ObjNotSet)
705711
End If
706712

707713
objType = o.GetType()
@@ -726,13 +732,15 @@ OptimisticSet As Boolean, RValueBase As Boolean)
726732

727733
NewValue = args(ArgCount)
728734
If NewValue IsNot Nothing Then
735+
729736
Dim elemType As Type
730737
elemType = objType.GetElementType()
731738

732739
'Check that the type is valid for the assignment
733740
If NewValue.GetType() IsNot elemType Then
734741
NewValue = ObjectType.CTypeHelper(NewValue, elemType)
735742
End If
743+
736744
End If
737745

738746
'Check for valid dimensions
@@ -747,17 +755,21 @@ OptimisticSet As Boolean, RValueBase As Boolean)
747755
ary.SetValue(NewValue, CInt(args(0)), CInt(args(1)))
748756

749757
Else
758+
750759
Dim IndexArray() As Integer
751760
Dim ArgIndex As Integer
752761
ReDim IndexArray(ArgCount - 1)
753762

754763
For ArgIndex = 0 To ArgCount - 1
755764
IndexArray(ArgIndex) = CInt(args(ArgIndex))
756-
Next ArgIndex
765+
Next
757766

758767
ary.SetValue(NewValue, IndexArray)
768+
759769
End If
770+
760771
Else
772+
761773
Dim flags As BindingFlags
762774
Dim member As MemberInfo
763775
Dim members As MemberInfo()
@@ -771,10 +783,12 @@ OptimisticSet As Boolean, RValueBase As Boolean)
771783
BindingFlags.Public
772784

773785
If objType.IsCOMObject() Then
786+
774787
CheckForClassExtendingCOMClass(objType)
775788
flags = flags Or GetPropertyPutFlags(args(args.GetUpperBound(0)))
776789

777790
Else
791+
778792
flags = flags Or BindingFlags.SetProperty
779793
If (args.Length = 1) Then
780794
flags = flags Or BindingFlags.SetField
@@ -816,15 +830,18 @@ OptimisticSet As Boolean, RValueBase As Boolean)
816830
' report a bug to the CLR.
817831
Debug.Assert(False)
818832
End Try
819-
Next i
833+
Next
834+
820835
End If
821836

822837
Dim binder As VBBinder
823838
binder = New VBBinder(Nothing)
824839
Try
840+
825841
If objType.IsCOMObject Then
826842
binder.InvokeMember("", flags, objType, objIReflect, o, args, paramnames)
827843
Else
844+
828845
Dim state As Object = Nothing
829846
Dim method As MethodBase
830847

@@ -857,13 +874,16 @@ OptimisticSet As Boolean, RValueBase As Boolean)
857874
End If
858875

859876
Catch ex As Exception When IsMissingMemberException(ex)
877+
860878
'Override the message so that we're consistent with above Throw
861879
Throw New MissingMemberException(SR.Format(SR.MissingMember_NoDefaultMemberFound1, VBFriendlyName(objType, o)))
862880

863881
Catch ex As TargetInvocationException
864882
Throw ex.InnerException
865883
End Try
884+
866885
End If
886+
867887
End Sub
868888

869889
Private Shared Function GetPropertyPutFlags(NewValue As Object) As BindingFlags

Community.VisualBasic/Community.VisualBasic/CompilerServices/NewLateBinding.vb

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ Namespace Global.Community.VisualBasic.CompilerServices
1818
' Implements VB late binder.
1919
<ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)>
2020
Public NotInheritable Class NewLateBinding
21+
2122
' Prevent creation.
2223
Private Sub New()
2324
End Sub
2425

2526
<DebuggerHiddenAttribute()> <DebuggerStepThroughAttribute()>
26-
Public Shared Function LateCall(
27-
Instance As Object,
28-
Type As System.Type,
29-
MemberName As String,
30-
Arguments As Object(),
31-
ArgumentNames As String(),
32-
TypeArguments As System.Type(),
33-
CopyBack As Boolean(),
34-
IgnoreReturn As Boolean) As Object
27+
Public Shared Function LateCall(Instance As Object,
28+
Type As System.Type,
29+
MemberName As String,
30+
Arguments As Object(),
31+
ArgumentNames As String(),
32+
TypeArguments As System.Type(),
33+
CopyBack As Boolean(),
34+
IgnoreReturn As Boolean) As Object
3535

3636
If Arguments Is Nothing Then Arguments = NoArguments
3737
If ArgumentNames Is Nothing Then ArgumentNames = NoArgumentNames
@@ -57,27 +57,25 @@ IgnoreReturn As Boolean) As Object
5757
<Obsolete("do not use this method", True)>
5858
<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>
5959
<DebuggerHiddenAttribute()> <DebuggerStepThroughAttribute()>
60-
Public Shared Function FallbackCall(
61-
Instance As Object,
62-
MemberName As String,
63-
Arguments As Object(),
64-
ArgumentNames As String(),
65-
IgnoreReturn As Boolean) As Object
60+
Public Shared Function FallbackCall(Instance As Object,
61+
MemberName As String,
62+
Arguments As Object(),
63+
ArgumentNames As String(),
64+
IgnoreReturn As Boolean) As Object
65+
66+
Return ObjectLateCall(Instance, Nothing, MemberName, Arguments, ArgumentNames, NoTypeArguments, IDOBinder.GetCopyBack(), IgnoreReturn)
6667

67-
Return ObjectLateCall(Instance, Nothing, MemberName, Arguments,
68-
ArgumentNames, NoTypeArguments, IDOBinder.GetCopyBack(), IgnoreReturn)
6968
End Function
7069

7170
<DebuggerHiddenAttribute()> <DebuggerStepThroughAttribute()>
72-
Private Shared Function ObjectLateCall(
73-
instance As Object,
74-
type As System.Type,
75-
memberName As String,
76-
arguments As Object(),
77-
argumentNames As String(),
78-
typeArguments As System.Type(),
79-
copyBack As Boolean(),
80-
ignoreReturn As Boolean) As Object
71+
Private Shared Function ObjectLateCall(instance As Object,
72+
type As System.Type,
73+
memberName As String,
74+
arguments As Object(),
75+
argumentNames As String(),
76+
typeArguments As System.Type(),
77+
copyBack As Boolean(),
78+
ignoreReturn As Boolean) As Object
8179

8280
Dim baseReference As Container
8381
If type IsNot Nothing Then
@@ -91,20 +89,21 @@ ignoreReturn As Boolean) As Object
9189

9290
Dim failure As ResolutionFailure
9391

94-
Return CallMethod(
95-
baseReference,
96-
memberName,
97-
arguments,
98-
argumentNames,
99-
typeArguments,
100-
copyBack,
101-
invocationFlags,
102-
True,
103-
failure)
92+
Return CallMethod(baseReference,
93+
memberName,
94+
arguments,
95+
argumentNames,
96+
typeArguments,
97+
copyBack,
98+
invocationFlags,
99+
True,
100+
failure)
101+
104102
End Function
105103

106104
'Quick check to determine if FallbackCall will succeed
107105
Friend Shared Function CanBindCall(instance As Object, memberName As String, arguments As Object(), argumentNames As String(), ignoreReturn As Boolean) As Boolean
106+
108107
Dim baseReference As New Container(instance)
109108
Dim invocationFlags As BindingFlags = BindingFlagsInvokeMethod Or BindingFlagsGetProperty
110109
If ignoreReturn Then invocationFlags = invocationFlags Or BindingFlagsIgnoreReturn
@@ -128,6 +127,7 @@ ignoreReturn As Boolean) As Object
128127
failure)
129128

130129
Return failure = ResolutionFailure.None
130+
131131
End Function
132132

133133
' LateCallInvokeDefault is used to optionally invoke the default action on a call target.
@@ -799,17 +799,15 @@ RValueBase As Boolean)
799799
<Obsolete("do not use this method", True)>
800800
<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>
801801
<DebuggerHiddenAttribute(), DebuggerStepThroughAttribute()>
802-
Public Shared Sub FallbackSetComplex(
803-
Instance As Object,
804-
MemberName As String,
805-
Arguments() As Object,
806-
OptimisticSet As Boolean,
807-
RValueBase As Boolean)
802+
Public Shared Sub FallbackSetComplex(Instance As Object,
803+
MemberName As String,
804+
Arguments() As Object,
805+
OptimisticSet As Boolean,
806+
RValueBase As Boolean)
808807

809-
ObjectLateSetComplex(
810-
Instance, Nothing, MemberName, Arguments, Array.Empty(Of String)(),
811-
NoTypeArguments, OptimisticSet, RValueBase)
812-
End Sub 'FallbackSetComplex
808+
ObjectLateSetComplex(Instance, Nothing, MemberName, Arguments, Array.Empty(Of String)(), NoTypeArguments, OptimisticSet, RValueBase)
809+
810+
End Sub
813811

814812
<DebuggerHiddenAttribute(), DebuggerStepThroughAttribute()>
815813
Friend Shared Sub ObjectLateSetComplex(

Community.VisualBasic/Community.VisualBasic/CompilerServices/Utils.LateBinder.vb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Namespace Global.Community.VisualBasic.CompilerServices
5757
Return name
5858
End Function
5959

60-
Friend Shared Function GetResourceString(ResourceId As vbErrors) As String
60+
Friend Shared Function GetResourceString(ResourceId As VbErrors) As String
6161
Dim id As String = "ID" & CStr(ResourceId)
6262
Return SR.GetResourceString(id, id)
6363
End Function
@@ -348,15 +348,17 @@ GetSpecialValue:
348348
End Function
349349

350350
Friend Shared Function VBFriendlyName(typ As System.Type, o As Object) As String
351+
351352
If typ.IsCOMObject AndAlso (typ.FullName = "System.__ComObject") Then
352-
#If WINDOWS Then
353-
Return TypeNameOfCOMObject(o, False)
354-
#Else
355-
Throw New PlatformNotSupportedException
356-
#End If
353+
If OperatingSystem.IsWindows Then
354+
Return TypeNameOfCOMObject(o, False)
355+
Else
356+
Throw New PlatformNotSupportedException
357+
End If
357358
End If
358359

359360
Return VBFriendlyNameOfType(typ)
361+
360362
End Function
361363

362364
Friend Shared Function VBFriendlyNameOfType(typ As System.Type, Optional fullName As Boolean = False) As String

0 commit comments

Comments
 (0)