diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Attributes/SourceAttributeData.vb b/src/Compilers/VisualBasic/Portable/Symbols/Attributes/SourceAttributeData.vb index a099411c97ce0a732e870d018e63bed660d47d91..e7ca3240df918a1ce0af7b89a96bf3cc47edc1ad 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Attributes/SourceAttributeData.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Attributes/SourceAttributeData.vb @@ -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 diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceEventSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceEventSymbol.vb index 84bb5557c613cbc889db8eaa833366088c5a9bb5..6b5dda094a44483c2dc438983e4c6f23508f3c42 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceEventSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceEventSymbol.vb @@ -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. diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceFieldSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceFieldSymbol.vb index 4fe5253ce83ecb95b16e7c48912834b31911f655..94a8ec2213f64add4d7a70ac34a9d77773a42494 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceFieldSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceFieldSymbol.vb @@ -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 diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb index 0551969138d01a2d4b9db8ee59af199094f12298..ac15fe5a960def0c45d507d87b2d9cf992c24115 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb @@ -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 diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceModuleSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceModuleSymbol.vb index e46d429c8969c8b10833b73b64833250d06c428f..6aeead2ce8641df1a6601086efd66acd9ec95ef9 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceModuleSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceModuleSymbol.vb @@ -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 diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol.vb index 5e7230aa615d01aff108642fa0a131088a402c41..aded4c98f53279b580e1fe682f43e284140c82fd 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol.vb @@ -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 diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceParameterSymbol.vb index 79ec2702744cf883357c7fc3de7020b0c38172fe..53314dec1aead20a48e92f97755e68ea51af4f2e 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceParameterSymbol.vb @@ -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) diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertyAccessorSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertyAccessorSymbol.vb index 2f1fffbe6efc18b2166d324cbf27cafbfadc1c21..e777b1dd8f2d6c94d79914525d89a9c753b89cc4 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertyAccessorSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertyAccessorSymbol.vb @@ -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 diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertySymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertySymbol.vb index 42e0e01db4c4c8dda267a087b76b7d66e32db4da..d53b4d90546833235f54ca38289f7741bbd4827a 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertySymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertySymbol.vb @@ -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) diff --git a/src/Compilers/VisualBasic/Test/Emit/Attributes/AttributeTests_Tuples.vb b/src/Compilers/VisualBasic/Test/Emit/Attributes/AttributeTests_Tuples.vb new file mode 100644 index 0000000000000000000000000000000000000000..561de0d704e77dea1bc2651784cabd3a733ad0bc --- /dev/null +++ b/src/Compilers/VisualBasic/Test/Emit/Attributes/AttributeTests_Tuples.vb @@ -0,0 +1,125 @@ +' 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} + + + Public Sub ExplicitTupleNamesAttribute() + Dim comp = CreateCompilationWithMscorlibAndVBRuntime( + + +Public Class C + + Public Field1 As ValueTuple(Of Integer, Integer) + + + Public ReadOnly Prop1 As ValueTuple(Of Integer, Integer) + + Public ReadOnly Property Prop2 As Integer + + Get + Return Nothing + End Get + End Property + + + Public Function M( x As ValueTuple) As ValueTuple(Of Integer, Integer) + Return (0, 0) + End Function + + Public Delegate Sub Delegate1(Of T)(sender As Object, args As ValueTuple(Of T)) + + + 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 + + + Default Public ReadOnly Property Item1( t As (a As Integer, b As Integer)) As (a As Integer, b As Integer) + Get + Return t + End Get + End Property +End Class + + +Public Structure S +End Structure + +]]> +, additionalRefs:=s_valueTupleRefs) + + comp.AssertTheseDiagnostics( + + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC31445: Attribute 'TupleElementNamesAttribute' cannot be applied to 'Get' of 'Prop2' because the attribute is not valid on this declaration type. + + ~~~~~~~~~~~~~~~~~ +BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names. + Public Function M( x As ValueTuple) As ValueTuple(Of Integer, Integer) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names. + Public Function M( x As ValueTuple) As 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, args As ValueTuple(Of T)) + ~~~~~~~~~~~~~~~~~~~~~~~~ +BC30662: Attribute 'TupleElementNamesAttribute' cannot be applied to 'Event1' because the attribute is not valid on this declaration type. + + ~~~~~~~~~~~~~~~~~ +BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37269: Cannot reference 'System.Runtime.CompilerServices.TupleElementNamesAttribute' explicitly. Use the tuple syntax to define tuple names. + Default Public ReadOnly Property Item1( 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. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ]]> +) + + End Sub + End Class +End Namespace diff --git a/src/Compilers/VisualBasic/Test/Emit/BasicCompilerEmitTest.vbproj b/src/Compilers/VisualBasic/Test/Emit/BasicCompilerEmitTest.vbproj index 54f3b093170cf3840dd49f3f24a5ccd77f7bc855..f23bf77fd1444a6ac127acc30cad2ead12b31e5d 100644 --- a/src/Compilers/VisualBasic/Test/Emit/BasicCompilerEmitTest.vbproj +++ b/src/Compilers/VisualBasic/Test/Emit/BasicCompilerEmitTest.vbproj @@ -75,6 +75,7 @@ + @@ -260,4 +261,4 @@ - + \ No newline at end of file