Skip to content

Commit

Permalink
React to string comparison changing on .NET Core (#56011)
Browse files Browse the repository at this point in the history
The default sort order for `char` / `string` changed on .NET Core. This
impacted a number of our tests which weren't explicitly using ordinal to
compare strings.

dotnet/runtime#43956
  • Loading branch information
jaredpar authored Aug 30, 2021
1 parent 3fdd28b commit 4d99cda
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 75 deletions.
17 changes: 9 additions & 8 deletions src/Compilers/Test/Utilities/VisualBasic/CompilationTestUtils.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1022,13 +1022,14 @@ Friend Module CompilationUtils
Dim diag2 = diagAndIndex2.Diagnostic
Dim loc1 = diag1.Location
Dim loc2 = diag2.Location
Dim comparer = StringComparer.Ordinal

If Not (loc1.IsInSource Or loc1.IsInMetadata) Then
If Not (loc2.IsInSource Or loc2.IsInMetadata) Then
' Both have no location. Sort by code, then by message.
If diag1.Code < diag2.Code Then Return -1
If diag1.Code > diag2.Code Then Return 1
Return diag1.GetMessage(EnsureEnglishUICulture.PreferredOrNull).CompareTo(diag2.GetMessage(EnsureEnglishUICulture.PreferredOrNull))
Return comparer.Compare(diag1.GetMessage(EnsureEnglishUICulture.PreferredOrNull), diag2.GetMessage(EnsureEnglishUICulture.PreferredOrNull))
Else
Return -1
End If
Expand All @@ -1039,24 +1040,24 @@ Friend Module CompilationUtils
Dim sourceTree1 = loc1.SourceTree
Dim sourceTree2 = loc2.SourceTree

If sourceTree1.FilePath <> sourceTree2.FilePath Then Return sourceTree1.FilePath.CompareTo(sourceTree2.FilePath)
If sourceTree1.FilePath <> sourceTree2.FilePath Then Return comparer.Compare(sourceTree1.FilePath, sourceTree2.FilePath)
If loc1.SourceSpan.Start < loc2.SourceSpan.Start Then Return -1
If loc1.SourceSpan.Start > loc2.SourceSpan.Start Then Return 1
If loc1.SourceSpan.Length < loc2.SourceSpan.Length Then Return -1
If loc1.SourceSpan.Length > loc2.SourceSpan.Length Then Return 1
If diag1.Code < diag2.Code Then Return -1
If diag1.Code > diag2.Code Then Return 1

Return diag1.GetMessage(EnsureEnglishUICulture.PreferredOrNull).CompareTo(diag2.GetMessage(EnsureEnglishUICulture.PreferredOrNull))
Return comparer.Compare(diag1.GetMessage(EnsureEnglishUICulture.PreferredOrNull), diag2.GetMessage(EnsureEnglishUICulture.PreferredOrNull))
ElseIf loc1.IsInMetadata AndAlso loc2.IsInMetadata Then
' sort by assembly name, then by error code
Dim name1 = loc1.MetadataModule.ContainingAssembly.Name
Dim name2 = loc2.MetadataModule.ContainingAssembly.Name
If name1 <> name2 Then Return name1.CompareTo(name2)
If name1 <> name2 Then Return comparer.Compare(name1, name2)
If diag1.Code < diag2.Code Then Return -1
If diag1.Code > diag2.Code Then Return 1

Return diag1.GetMessage(EnsureEnglishUICulture.PreferredOrNull).CompareTo(diag2.GetMessage(EnsureEnglishUICulture.PreferredOrNull))
Return comparer.Compare(diag1.GetMessage(EnsureEnglishUICulture.PreferredOrNull), diag2.GetMessage(EnsureEnglishUICulture.PreferredOrNull))
ElseIf loc1.IsInSource Then
Return -1
ElseIf loc2.IsInSource Then
Expand Down Expand Up @@ -1145,9 +1146,9 @@ Friend Module CompilationUtils
Loop

If (isDistinct) Then
symType = (From temp In symType Distinct Select temp Order By temp.ToDisplayString()).ToList()
symType = symType.Distinct().OrderBy(Function(x) x.ToDisplayString(), StringComparer.OrdinalIgnoreCase).ToList()
Else
symType = (From temp In symType Select temp Order By temp.ToDisplayString()).ToList()
symType = symType.OrderBy(Function(x) x.ToDisplayString(), StringComparer.OrdinalIgnoreCase).ToList()
End If
Return symType

Expand All @@ -1162,7 +1163,7 @@ Friend Module CompilationUtils
Dim bindings1 = compilation.GetSemanticModel(tree)
Dim symbols = GetTypeSymbol(compilation, treeName, symbolName, isDistinct)
Assert.Equal(ExpectedDispName.Count, symbols.Count)
ExpectedDispName = (From temp In ExpectedDispName Select temp Order By temp).ToArray()
ExpectedDispName = ExpectedDispName.OrderBy(StringComparer.OrdinalIgnoreCase).ToArray()
Dim count = 0
For Each item In symbols
Assert.NotNull(item)
Expand Down
5 changes: 2 additions & 3 deletions src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenVBCore.vb
Original file line number Diff line number Diff line change
Expand Up @@ -2795,9 +2795,9 @@ End Namespace
references:={SystemCoreRef, SystemXmlLinqRef, SystemXmlRef})

CompilationUtils.AssertTheseDiagnostics(compilation1,
<errors>BC30560: Error in project-level import 'Microsoft.VisualBasic' at 'Microsoft.VisualBasic' : 'VisualBasic' is ambiguous in the namespace 'Microsoft'.
BC30560: 'VisualBasic' is ambiguous in the namespace 'Microsoft'.
<errors>BC30560: 'VisualBasic' is ambiguous in the namespace 'Microsoft'.
BC30560: 'VisualBasic' is ambiguous in the namespace 'Microsoft'.
BC30560: Error in project-level import 'Microsoft.VisualBasic' at 'Microsoft.VisualBasic' : 'VisualBasic' is ambiguous in the namespace 'Microsoft'.
BC30560: 'VisualBasic' is ambiguous in the namespace 'Microsoft'.
Imports Microsoft.VisualBasic
~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -2807,7 +2807,6 @@ BC30560: 'VisualBasic' is ambiguous in the namespace 'Microsoft'.
BC31210: module 'VisualBasic' conflicts with a Visual Basic Runtime namespace 'VisualBasic'.
Public Module VisualBasic
~~~~~~~~~~~

</errors>)

' Remove the reference to System.XML.Linq and verify compilation behavior that the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2673,10 +2673,10 @@ Public Class C
End Class]]>.Value

Dim expectedDiagnostics = <![CDATA[
BC33038: Type 'C' must define operator '-' to be used in a 'For' statement.
BC33038: Type 'C' must define operator '+' to be used in a 'For' statement.
For i = init To limit Step [step]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC33038: Type 'C' must define operator '+' to be used in a 'For' statement.
BC33038: Type 'C' must define operator '-' to be used in a 'For' statement.
For i = init To limit Step [step]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC33038: Type 'C' must define operator '<=' to be used in a 'For' statement.
Expand Down Expand Up @@ -2784,10 +2784,10 @@ Public Structure C
End Structure]]>.Value

Dim expectedDiagnostics = <![CDATA[
BC33038: Type 'C?' must define operator '-' to be used in a 'For' statement.
BC33038: Type 'C?' must define operator '+' to be used in a 'For' statement.
For i = init To limit Step [step]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC33038: Type 'C?' must define operator '+' to be used in a 'For' statement.
BC33038: Type 'C?' must define operator '-' to be used in a 'For' statement.
For i = init To limit Step [step]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC33038: Type 'C?' must define operator '<=' to be used in a 'For' statement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5200,10 +5200,10 @@ End Module </file>
BC30311: Value of type 'Integer' cannot be converted to 'base'.
For i = New base To New first()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC33038: Type 'base' must define operator '-' to be used in a 'For' statement.
BC33038: Type 'base' must define operator '+' to be used in a 'For' statement.
For j = New base To New first() step new second()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC33038: Type 'base' must define operator '+' to be used in a 'For' statement.
BC33038: Type 'base' must define operator '-' to be used in a 'For' statement.
For j = New base To New first() step new second()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC33038: Type 'base' must define operator '&lt;=' to be used in a 'For' statement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ Imports System
' Outside the method, all B's are available.
syms = semanticModel.LookupSymbols(posOutside, Nothing, "b", Nothing)
Assert.Equal(3, syms.Length)
Dim fullNames = From s In syms.AsEnumerable Order By s.ToTestDisplayString() Select s.ToTestDisplayString()
Dim fullNames = syms.Select(Function(x) x.ToTestDisplayString()).OrderBy(StringComparer.Ordinal).ToArray()
Assert.Equal("A.B(Of X)", fullNames(0))
Assert.Equal("A.B(Of X, Y)", fullNames(1))
Assert.Equal("B", fullNames(2))

' Inside the method, all B's are available if only types/namespace are allowed
syms = semanticModel.LookupNamespacesAndTypes(posOutside, Nothing, "b")
Assert.Equal(3, syms.Length)
fullNames = From s In syms.AsEnumerable Order By s.ToTestDisplayString() Select s.ToTestDisplayString()
fullNames = syms.Select(Function(x) x.ToTestDisplayString()).OrderBy(StringComparer.Ordinal).ToArray()
Assert.Equal("A.B(Of X)", fullNames(0))
Assert.Equal("A.B(Of X, Y)", fullNames(1))
Assert.Equal("B", fullNames(2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ End Namespace
Dim actual_lookupSymbols = GetLookupSymbols(compilation, "a.vb", name:="F1", includeReducedExtensionMethods:=True)

Assert.Equal(2, actual_lookupSymbols.Count)
Dim sortedMethodGroup = actual_lookupSymbols.AsEnumerable().OrderBy(Function(s) s.ToTestDisplayString()).ToArray()
Dim sortedMethodGroup = actual_lookupSymbols.AsEnumerable().OrderBy(Function(s) s.ToTestDisplayString(), StringComparer.Ordinal).ToArray()
Assert.Equal("Function C1.F1() As System.Int32", sortedMethodGroup(0).ToTestDisplayString())
Assert.Equal("Function C1.F1(x As System.Int32) As System.Int32", sortedMethodGroup(1).ToTestDisplayString())
End Sub
Expand Down Expand Up @@ -410,7 +410,7 @@ End Namespace
actual_lookupSymbols = GetLookupSymbols(compilation, "a.vb", name:="Test1", container:=c1, includeReducedExtensionMethods:=True)

Assert.Equal(8, actual_lookupSymbols.Count)
Dim sortedMethodGroup = actual_lookupSymbols.AsEnumerable().OrderBy(Function(s) s.ToTestDisplayString()).ToArray()
Dim sortedMethodGroup = actual_lookupSymbols.AsEnumerable().OrderBy(Function(s) s.ToTestDisplayString(), StringComparer.Ordinal).ToArray()
Dim expected() As String = {"Sub NS1.NS2.Module1.C1.Test1(Of T1)()",
"Sub NS1.NS2.Module1.C1.Test1(Of T1, T2)()",
"Sub NS1.NS2.Module1.C1.Test1(Of T1, T2, T3)()",
Expand Down Expand Up @@ -531,7 +531,7 @@ End Namespace
Dim actual_lookupSymbols = GetLookupSymbols(compilation, "a.vb", name:="Test1", includeReducedExtensionMethods:=True)

Assert.Equal(8, actual_lookupSymbols.Count)
Dim sortedMethodGroup = actual_lookupSymbols.AsEnumerable().OrderBy(Function(s) s.ToTestDisplayString()).ToArray()
Dim sortedMethodGroup = actual_lookupSymbols.AsEnumerable().OrderBy(Function(s) s.ToTestDisplayString(), StringComparer.Ordinal).ToArray()
Dim expected() As String = {"Sub NS1.NS2.Module1.C1.Test1(Of T1)()",
"Sub NS1.NS2.Module1.C1.Test1(Of T1, T2)()",
"Sub NS1.NS2.Module1.C1.Test1(Of T1, T2, T3)()",
Expand Down Expand Up @@ -658,7 +658,7 @@ End Namespace
actual_lookupSymbols = GetLookupSymbols(compilation, "a.vb", name:="Test1", container:=c1, includeReducedExtensionMethods:=True)

Assert.Equal(8, actual_lookupSymbols.Count)
Dim sortedMethodGroup = actual_lookupSymbols.AsEnumerable().OrderBy(Function(s) s.ToTestDisplayString()).ToArray()
Dim sortedMethodGroup = actual_lookupSymbols.AsEnumerable().OrderBy(Function(s) s.ToTestDisplayString(), StringComparer.Ordinal).ToArray()
Dim expected() As String = {"Sub NS1.NS2.Module1.C1.Test1(Of T1)()",
"Sub NS1.NS2.Module1.C1.Test1(Of T1, T2)()",
"Sub NS1.NS2.Module1.C1.Test1(Of T1, T2, T3)()",
Expand Down Expand Up @@ -784,7 +784,7 @@ End Namespace
actual_lookupSymbols = GetLookupSymbols(compilation, "a.vb", name:="Test1", container:=t, includeReducedExtensionMethods:=True)

Assert.Equal(8, actual_lookupSymbols.Count)
Dim sortedMethodGroup = actual_lookupSymbols.AsEnumerable().OrderBy(Function(s) s.ToTestDisplayString()).ToArray()
Dim sortedMethodGroup = actual_lookupSymbols.AsEnumerable().OrderBy(Function(s) s.ToTestDisplayString(), StringComparer.Ordinal).ToArray()
Dim expected() As String = {"Sub T.Test1(Of T1)()",
"Sub T.Test1(Of T1, T2)()",
"Sub T.Test1(Of T1, T2, T3)()",
Expand Down
Loading

0 comments on commit 4d99cda

Please sign in to comment.