Skip to content

Internal VB type comparisons do not ignore custom modifiers when requested to #41319

@chsienki

Description

@chsienki

When comparing symbols internally in the compiler, it is possible to pass the TypeCompareKind which specifies the strictness of the comparison.

In VB there is an option TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds which should allow two types which differ only by the presence of custom modifiers to compare equally.

Consider:

Compilation:

Namespace N
    Public Class A(Of T)
        Public Function M(t As A(Of T)) As A(Of T)
            t.M(t)
            Return t
        End Function
    End Class
End Namespace

Test:

Dim syntaxTree = compilation.SyntaxTrees(0)
Dim root = syntaxTree.GetRoot()
Dim model = compilation.GetSemanticModel(syntaxTree)

Dim aSyntax = CType(root.DescendantNodes().First(Function(sn) sn.Kind() = SyntaxKind.ClassBlock), Syntax.ClassBlockSyntax)
Dim aSymbol = CType(model.GetDeclaredSymbol(aSyntax), NamedTypeSymbol)

Dim modifiers = ImmutableArray.Create(VisualBasicCustomModifier.CreateOptional(compilation.GetSpecialType(SpecialType.System_Object)))
Dim substitutedTypes = ImmutableArray.Create((New TypeWithModifiers(aSymbol.TypeParameters.Single(), modifiers)))
Dim modSymbol = aSymbol.Construct(TypeSubstitution.Create(aSymbol, aSymbol.TypeParameters, substitutedTypes))

Dim method1 = CType(aSymbol.GetMembers("M").Single(), IMethodSymbol)      ' A(Of T).M(t AS A(Of T)) As A(Of T)
Dim method2 = CType(modSymbol.GetMembers("M").Single(), IMethodSymbol)    ' A(Of T modopt(Object)).M(t AS A(Of T modopt(Object)) AS A(Of T modopt(Object))

method1 and method2 should compare equal when ignoring custom modifiers and not equal by default.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions