提交 195e7ad1 编写于 作者: V VSadov

Explicit use of TupleElementNames

上级 75a042bf
......@@ -166,6 +166,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End If
targetType = CByte(targetInfo.Underlying)
ElseIf parameterType.IsArrayType Then
specType = DirectCast(parameterType, ArrayTypeSymbol).ElementType.SpecialType
End If
Select Case targetType
......@@ -233,6 +237,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
foundMatch = parameterType = lazySystemType
k += 1
Case CByte(SignatureTypeCode.SZArray)
' skip over and check the next byte
foundMatch = parameterType.IsArrayType
Case Else
Return -1
End Select
......
......@@ -642,8 +642,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Friend Overrides Sub DecodeWellKnownAttribute(ByRef arguments As DecodeWellKnownAttributeArguments(Of AttributeSyntax, VisualBasicAttributeData, AttributeLocation))
Debug.Assert(arguments.AttributeSyntaxOpt IsNot Nothing)
Dim attrData = arguments.Attribute
If attrData.IsTargetAttribute(Me, AttributeDescription.TupleElementNamesAttribute) Then
arguments.Diagnostics.Add(ERRID.ERR_ExplicitTupleElementNames, arguments.AttributeSyntaxOpt.Location)
End If
If attrData.IsTargetAttribute(Me, AttributeDescription.NonSerializedAttribute) Then
' Although NonSerialized attribute is only applicable on fields we relax that restriction and allow application on events as well
' to allow making the backing field non-serializable.
......
......@@ -310,6 +310,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Dim attrData = arguments.Attribute
Debug.Assert(arguments.SymbolPart = AttributeLocation.None)
If attrData.IsTargetAttribute(Me, AttributeDescription.TupleElementNamesAttribute) Then
arguments.Diagnostics.Add(ERRID.ERR_ExplicitTupleElementNames, arguments.AttributeSyntaxOpt.Location)
End If
If attrData.IsTargetAttribute(Me, AttributeDescription.SpecialNameAttribute) Then
arguments.GetOrCreateData(Of CommonFieldWellKnownAttributeData)().HasSpecialNameAttribute = True
ElseIf attrData.IsTargetAttribute(Me, AttributeDescription.NonSerializedAttribute) Then
......
......@@ -1560,6 +1560,10 @@ lReportErrorOnTwoTokens:
Dim attrData = arguments.Attribute
Debug.Assert(Not attrData.HasErrors)
If attrData.IsTargetAttribute(Me, AttributeDescription.TupleElementNamesAttribute) Then
arguments.Diagnostics.Add(ERRID.ERR_ExplicitTupleElementNames, arguments.AttributeSyntaxOpt.Location)
End If
If arguments.SymbolPart = AttributeLocation.Return Then
' Decode well-known attributes applied to return value
......
......@@ -1054,6 +1054,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Debug.Assert(Not attrData.HasErrors)
Debug.Assert(arguments.SymbolPart = AttributeLocation.None)
If attrData.IsTargetAttribute(Me, AttributeDescription.TupleElementNamesAttribute) Then
arguments.Diagnostics.Add(ERRID.ERR_ExplicitTupleElementNames, arguments.AttributeSyntaxOpt.Location)
End If
If attrData.IsTargetAttribute(Me, AttributeDescription.DefaultCharSetAttribute) Then
Dim charSet As CharSet = attrData.GetConstructorArgument(Of CharSet)(0, SpecialType.System_Enum)
If Not CommonModuleWellKnownAttributeData.IsValidCharSet(charSet) Then
......
......@@ -2126,6 +2126,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
' If we start caching information about ComSourceInterfacesAttribute here, implementation of HasComSourceInterfacesAttribute function should be changed accordingly.
' If we start caching information about ComVisibleAttribute here, implementation of GetComVisibleState function should be changed accordingly.
If attrData.IsTargetAttribute(Me, AttributeDescription.TupleElementNamesAttribute) Then
arguments.Diagnostics.Add(ERRID.ERR_ExplicitTupleElementNames, arguments.AttributeSyntaxOpt.Location)
End If
Dim decoded As Boolean = False
Select Case Me.TypeKind
......
......@@ -290,6 +290,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
' InAttribute, OutAttribute
' - metadata flag set, no diagnostics reported, don't influence language semantics
If attrData.IsTargetAttribute(Me, AttributeDescription.TupleElementNamesAttribute) Then
arguments.Diagnostics.Add(ERRID.ERR_ExplicitTupleElementNames, arguments.AttributeSyntaxOpt.Location)
End If
If attrData.IsTargetAttribute(Me, AttributeDescription.DefaultParameterValueAttribute) Then
' Attribute decoded and constant value stored during EarlyDecodeWellKnownAttribute.
DecodeDefaultParameterValueAttribute(AttributeDescription.DefaultParameterValueAttribute, arguments)
......
......@@ -475,7 +475,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End Function
Friend Overrides Sub DecodeWellKnownAttribute(ByRef arguments As DecodeWellKnownAttributeArguments(Of AttributeSyntax, VisualBasicAttributeData, AttributeLocation))
If arguments.SymbolPart = AttributeLocation.None Then
If arguments.Attribute.IsTargetAttribute(Me, AttributeDescription.DebuggerHiddenAttribute) Then
arguments.GetOrCreateData(Of MethodWellKnownAttributeData)().IsPropertyAccessorWithDebuggerHiddenAttribute = True
......
......@@ -543,6 +543,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Debug.Assert(arguments.AttributeSyntaxOpt IsNot Nothing)
Dim attrData = arguments.Attribute
If attrData.IsTargetAttribute(Me, AttributeDescription.TupleElementNamesAttribute) Then
arguments.Diagnostics.Add(ERRID.ERR_ExplicitTupleElementNames, arguments.AttributeSyntaxOpt.Location)
End If
If arguments.SymbolPart = AttributeLocation.Return Then
Dim isMarshalAs = attrData.IsTargetAttribute(Me, AttributeDescription.MarshalAsAttribute)
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports System.Globalization
Imports System.IO
Imports System.Reflection
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Xml.Linq
Imports Microsoft.CodeAnalysis.Test.Utilities
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Roslyn.Test.Utilities
Imports TypeKind = Microsoft.CodeAnalysis.TypeKind
Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics
Public Class AttributeTests_Tuples
Inherits BasicTestBase
ReadOnly s_valueTupleRefs As MetadataReference() = New MetadataReference() {ValueTupleRef, SystemRuntimeFacadeRef}
<Fact>
Public Sub ExplicitTupleNamesAttribute()
Dim comp = CreateCompilationWithMscorlibAndVBRuntime(
<compilation name="NoTuples">
<file name="a.vb"><![CDATA[
Imports System
Imports System.Runtime.CompilerServices
<TupleElementNames({"a", "b"})>
Public Class C
<TupleElementNames({Nothing, Nothing})>
Public Field1 As ValueTuple(Of Integer, Integer)
<TupleElementNames({"x", "y"})>
Public ReadOnly Prop1 As ValueTuple(Of Integer, Integer)
Public ReadOnly Property Prop2 As Integer
<TupleElementNames({"x", "y"})>
Get
Return Nothing
End Get
End Property
Public Function M(<TupleElementNames({Nothing})> x As ValueTuple) As <TupleElementNames({Nothing, Nothing})> ValueTuple(Of Integer, Integer)
Return (0, 0)
End Function
Public Delegate Sub Delegate1(Of T)(sender As Object, <TupleElementNames({"x"})> args As ValueTuple(Of T))
<TupleElementNames({"y"})>
Public Custom Event Event1 As Delegate1(Of ValueTuple(Of Integer))
AddHandler(value As Delegate1(Of ValueTuple(Of Integer)))
End AddHandler
RemoveHandler(value As Delegate1(Of ValueTuple(Of Integer)))
End RemoveHandler
RaiseEvent(sender As Object, args As ValueTuple(Of ValueTuple(Of Integer)))
End RaiseEvent
End Event
<TupleElementNames({"a", "b"})>
Default Public ReadOnly Property Item1(<TupleElementNames> t As (a As Integer, b As Integer)) As (a As Integer, b As Integer)
Get
Return t
End Get
End Property
End Class
<TupleElementNames({"a", "b"})>
Public Structure S
End Structure
]]></file>
</compilation>, additionalRefs:=s_valueTupleRefs)
comp.AssertTheseDiagnostics(
<errors>
<![CDATA[
BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names.
<TupleElementNames({"a", "b"})>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names.
<TupleElementNames({Nothing, Nothing})>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names.
<TupleElementNames({"x", "y"})>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC31445: Attribute 'TupleElementNamesAttribute' cannot be applied to 'Get' of 'Prop2' because the attribute is not valid on this declaration type.
<TupleElementNames({"x", "y"})>
~~~~~~~~~~~~~~~~~
BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names.
Public Function M(<TupleElementNames({Nothing})> x As ValueTuple) As <TupleElementNames({Nothing, Nothing})> ValueTuple(Of Integer, Integer)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names.
Public Function M(<TupleElementNames({Nothing})> x As ValueTuple) As <TupleElementNames({Nothing, Nothing})> ValueTuple(Of Integer, Integer)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names.
Public Delegate Sub Delegate1(Of T)(sender As Object, <TupleElementNames({"x"})> args As ValueTuple(Of T))
~~~~~~~~~~~~~~~~~~~~~~~~
BC30662: Attribute 'TupleElementNamesAttribute' cannot be applied to 'Event1' because the attribute is not valid on this declaration type.
<TupleElementNames({"y"})>
~~~~~~~~~~~~~~~~~
BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names.
<TupleElementNames({"a", "b"})>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names.
Default Public ReadOnly Property Item1(<TupleElementNames> t As (a As Integer, b As Integer)) As (a As Integer, b As Integer)
~~~~~~~~~~~~~~~~~
BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names.
<TupleElementNames({"a", "b"})>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
]]>
</errors>)
End Sub
End Class
End Namespace
......@@ -75,6 +75,7 @@
<Compile Include="AssemblyAttributes.vb" />
<Compile Include="Attributes\AssemblyAttributes.vb" />
<Compile Include="Attributes\AttributeTests.vb" />
<Compile Include="Attributes\AttributeTests_Tuples.vb" />
<Compile Include="Attributes\AttributeTests_Conditional.vb" />
<Compile Include="Attributes\AttributeTests_MarshalAs.vb" />
<Compile Include="Attributes\AttributeTests_ObsoleteAttribute.vb" />
......@@ -260,4 +261,4 @@
</ItemGroup>
<Import Project="..\..\..\..\..\build\Targets\VSL.Imports.targets" />
<Import Project="..\..\..\..\..\build\Targets\Roslyn.Toolsets.Xunit.targets" />
</Project>
</Project>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册