提交 78f341aa 编写于 作者: V VSadov

Implemented CommonCreateTupleTypeSymbol APIs

上级 87ba2772
......@@ -2594,11 +2594,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Function
Protected Overrides Function CommonCreateTupleTypeSymbol(elementTypes As ImmutableArray(Of ITypeSymbol), elementNames As ImmutableArray(Of String)) As INamedTypeSymbol
Throw New NotSupportedException(VBResources.TuplesNotSupported)
Dim vbElementTypes = elementTypes.SelectAsArray(Function(t) t.EnsureVbSymbolOrNothing(Of TypeSymbol)(NameOf(elementTypes)))
Return TupleTypeSymbol.Create(locationOpt:=Nothing, elementTypes:=vbElementTypes, elementLocations:=Nothing, elementNames:=elementNames, compilation:=Me)
End Function
Protected Overrides Function CommonCreateTupleTypeSymbol(underlyingType As INamedTypeSymbol, elementNames As ImmutableArray(Of String)) As INamedTypeSymbol
Throw New NotSupportedException(VBResources.TuplesNotSupported)
Return TupleTypeSymbol.Create(
locationOpt:=Nothing,
tupleCompatibleType:=underlyingType.EnsureVbSymbolOrNothing(Of NamedTypeSymbol)(NameOf(underlyingType)),
elementLocations:=Nothing,
elementNames:=elementNames)
End Function
Protected Overrides Function CommonCreatePointerTypeSymbol(elementType As ITypeSymbol) As IPointerTypeSymbol
......
......@@ -12315,15 +12315,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Tuples are not supported in VB..
'''</summary>
Friend ReadOnly Property TuplesNotSupported() As String
Get
Return ResourceManager.GetString("TuplesNotSupported", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Type argument cannot be Nothing.
'''</summary>
......
......@@ -5361,9 +5361,6 @@
<data name="ERR_PeWritingFailure" xml:space="preserve">
<value>An error occurred while writing the output file: {0}</value>
</data>
<data name="TuplesNotSupported" xml:space="preserve">
<value>Tuples are not supported in VB.</value>
</data>
<data name="ERR_OptionMustBeAbsolutePath" xml:space="preserve">
<value>Option '{0}' must be an absolute path.</value>
</data>
......
......@@ -1206,18 +1206,36 @@ BC2014: the value '_' is invalid for option 'RootNamespace'
Assert.Throws(Of NotSupportedException)(Function() compilation.CreatePointerTypeSymbol(Nothing))
End Sub
<Fact()>
<CompilerTrait(CompilerFeature.Tuples)>
Public Sub TuplesNotSupported2()
Dim compilation = VisualBasicCompilation.Create("HelloWorld")
Assert.Throws(Of NotSupportedException)(Function() compilation.CreateTupleTypeSymbol(New ImmutableArray(Of ITypeSymbol), New ImmutableArray(Of String)))
<Fact>
Public Sub CreateTupleTypeSymbol_NoNames()
Dim comp = VisualBasicCompilation.Create("test", references:={MscorlibRef}) ' no ValueTuple
Dim intType As TypeSymbol = comp.GetSpecialType(SpecialType.System_Int32)
Dim stringType As TypeSymbol = comp.GetSpecialType(SpecialType.System_String)
Dim vt2 = comp.GetWellKnownType(WellKnownType.System_ValueTuple_T2).Construct(intType, stringType)
Dim tupleWithoutNames = comp.CreateTupleTypeSymbol(vt2, Nothing)
Assert.True(tupleWithoutNames.IsTupleType)
Assert.Equal("(System.Int32, System.String)", tupleWithoutNames.ToTestDisplayString())
Assert.True(tupleWithoutNames.TupleElementNames.IsDefault)
Assert.Equal({"System.Int32", "System.String"}, tupleWithoutNames.TupleElementTypes.Select(Function(t) t.ToTestDisplayString()))
Assert.Equal(CInt(SymbolKind.NamedType), CInt(tupleWithoutNames.Kind))
End Sub
<Fact()>
<CompilerTrait(CompilerFeature.Tuples)>
Public Sub TuplesNotSupported()
Dim compilation = VisualBasicCompilation.Create("HelloWorld")
Assert.Throws(Of NotSupportedException)(Function() compilation.CreateTupleTypeSymbol(underlyingType:=Nothing, elementNames:=New ImmutableArray(Of String)))
<Fact>
Public Sub CreateTupleTypeSymbol_WithNames()
Dim comp = VisualBasicCompilation.Create("test", references:={MscorlibRef}) ' no ValueTuple
Dim intType As TypeSymbol = comp.GetSpecialType(SpecialType.System_Int32)
Dim stringType As TypeSymbol = comp.GetSpecialType(SpecialType.System_String)
Dim vt2 = comp.GetWellKnownType(WellKnownType.System_ValueTuple_T2).Construct(intType, stringType)
Dim tupleWithNames = comp.CreateTupleTypeSymbol(vt2, ImmutableArray.Create("Alice", "Bob"))
Assert.True(tupleWithNames.IsTupleType)
Assert.Equal("(Alice As System.Int32, Bob As System.String)", tupleWithNames.ToTestDisplayString())
Assert.Equal({"Alice", "Bob"}, tupleWithNames.TupleElementNames)
Assert.Equal({"System.Int32", "System.String"}, tupleWithNames.TupleElementTypes.Select(Function(t) t.ToTestDisplayString()))
Assert.Equal(SymbolKind.NamedType, tupleWithNames.Kind)
End Sub
<Fact()>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册