提交 a7c027ef 编写于 作者: A AlekseyTs

VB: Define special error type symbol to represent a pointer type, enables...

VB: Define special error type symbol to represent a pointer type, enables accurate comparison of signatures of methods imported from metadata.
***NO_CI***
 (changeset 1383354)
上级 0587bdac
......@@ -689,6 +689,7 @@
<Compile Include="Symbols\OverriddenMembersResult.vb" />
<Compile Include="Symbols\ParameterSymbol.vb" />
<Compile Include="Symbols\PEOrSourceOrMergedNamespaceSymbol.vb" />
<Compile Include="Symbols\PointerTypeSymbol.vb" />
<Compile Include="Symbols\PreprocessingSymbol.vb" />
<Compile Include="Symbols\PropertySignatureComparer.vb" />
<Compile Include="Symbols\PropertySymbol.vb" />
......
......@@ -329,7 +329,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
' And then hash that with the "T" type.
Dim hashCode = 0
Dim current As ITypeSymbol = Me
Dim current As TypeSymbol = Me
While (current.TypeKind = TypeKind.Array)
Dim cur = DirectCast(current, ArrayTypeSymbol)
hashCode = Hash.Combine(cur.Rank, hashCode)
......
......@@ -230,7 +230,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE
End Function
Protected Overrides Function MakePointerTypeSymbol(type As TypeSymbol, customModifiers As ImmutableArray(Of ModifierInfo)) As TypeSymbol
Return GetUnsupportedMetadataTypeSymbol()
Return New PointerTypeSymbol(type, VisualBasicCustomModifier.Convert(customModifiers))
End Function
Protected Overrides Function SubstituteWithUnboundIfGeneric(type As TypeSymbol) As TypeSymbol
......
Imports System.Collections.Immutable
' Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
''' <summary>
''' An error type symbol to represent a pointer type.
''' Pointer types are not supported by VB language, but internally
''' we need to be able to match them in signatures of methods
''' imported from metadata.
''' </summary>
Friend NotInheritable Class PointerTypeSymbol
Inherits ErrorTypeSymbol
Private ReadOnly m_PointedAtType As TypeSymbol
Private ReadOnly m_CustomModifiers As ImmutableArray(Of CustomModifier)
Public Sub New(pointedAtType As TypeSymbol, customModifiers As ImmutableArray(Of CustomModifier))
Debug.Assert(pointedAtType IsNot Nothing)
m_PointedAtType = pointedAtType
m_CustomModifiers = customModifiers.NullToEmpty()
End Sub
Friend Overrides ReadOnly Property MangleName As Boolean
Get
Return False
End Get
End Property
Friend Overrides ReadOnly Property ErrorInfo As DiagnosticInfo
Get
Return ErrorFactory.ErrorInfo(ERRID.ERR_UnsupportedType1, String.Empty)
End Get
End Property
Public Overrides Function GetHashCode() As Integer
' We don't want to blow the stack if we have a type like T***************...***,
' so we do not recurse until we have a non-pointer.
Dim indirections As Integer = 0
Dim current As PointerTypeSymbol = Me
Dim last As TypeSymbol
Do
indirections += 1
last = current.m_PointedAtType
current = TryCast(last, PointerTypeSymbol)
Loop While current IsNot Nothing
Return Hash.Combine(last, indirections)
End Function
Public Overrides Function Equals(obj As Object) As Boolean
If Me Is obj Then
Return True
End If
Dim other = TryCast(obj, PointerTypeSymbol)
Return other IsNot Nothing AndAlso other.m_PointedAtType.Equals(m_PointedAtType) AndAlso other.m_CustomModifiers.SequenceEqual(m_CustomModifiers)
End Function
End Class
End Namespace
......@@ -207,7 +207,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
If Not t1IsDefinition Then ' This is a generic instantiation
If t1.OriginalDefinition IsNot t2.OriginalDefinition Then
If t1.OriginalDefinition <> t2.OriginalDefinition Then
Return False ' different definition
End If
......
......@@ -93,7 +93,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Symbols.Metadata.PE
Dim p6Type As TypeSymbol = p6.Type
Assert.IsType(Of UnsupportedMetadataTypeSymbol)(p6Type)
Assert.IsType(Of PointerTypeSymbol)(p6Type)
Assert.Equal(ERRID.ERR_UnsupportedType1, p6Type.GetUseSiteErrorInfo().Code)
Assert.False(m7.IsSub)
Assert.Equal(1, m7.ReturnTypeCustomModifiers.Length)
......
......@@ -6824,6 +6824,85 @@ BC31417: 'Friend Overrides Property Set r(Value As Object)' cannot override 'Fri
End Sub
End Class
<WorkItem(1067044, "DevDiv")>
<Fact>
Sub Bug1067044()
Dim il = <![CDATA[
.class public abstract auto ansi beforefieldinit C1
extends [mscorlib]System.Object
{
.method public hidebysig newslot abstract virtual
instance int32* M1() cil managed
{
} // end of method C1::M1
.method family hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method C1::.ctor
} // end of class C1
.class public abstract auto ansi beforefieldinit C2
extends C1
{
.method public hidebysig virtual instance int32*
M1() cil managed
{
// Code size 8 (0x8)
.maxstack 1
.locals init (int32* V_0)
IL_0000: nop
IL_0001: ldc.i4.0
IL_0002: conv.u
IL_0003: stloc.0
IL_0004: br.s IL_0006
IL_0006: ldloc.0
IL_0007: ret
} // end of method C2::M1
.method public hidebysig newslot abstract virtual
instance void M2() cil managed
{
} // end of method C2::M2
.method family hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void C1::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method C2::.ctor
} // end of class C2
]]>
Dim source =
<compilation>
<file name="a.vb">
Public Class C3
Inherits C2
Public Overrides Sub M2()
End Sub
End Class
</file>
</compilation>
Dim compilation = CreateCompilationWithCustomILSource(source, il.Value, options:=TestOptions.DebugDll)
CompileAndVerify(compilation)
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册