Skip to content

Commit

Permalink
Report inappropriate OverloadResolutionPriority attribute applications
Browse files Browse the repository at this point in the history
See corresponding speclet chnages - dotnet/vblang#628
  • Loading branch information
AlekseyTs committed Dec 12, 2024
1 parent efeb43a commit cde583e
Show file tree
Hide file tree
Showing 21 changed files with 553 additions and 70 deletions.
2 changes: 2 additions & 0 deletions src/Compilers/VisualBasic/Portable/Errors/ErrorFacts.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
ERRID.ERR_UnsupportedRefReturningCallInWithStatement,
ERRID.ERR_TypeReserved,
ERRID.ERR_UnmanagedConstraintNotSatisfied,
ERRID.ERR_CannotApplyOverloadResolutionPriorityToOverride,
ERRID.ERR_CannotApplyOverloadResolutionPriorityToMember,
ERRID.ERR_NextAvailable,
ERRID.WRN_UseOfObsoleteSymbol2,
ERRID.WRN_InvalidOverrideDueToTupleNames2,
Expand Down
6 changes: 5 additions & 1 deletion src/Compilers/VisualBasic/Portable/Errors/Errors.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
ERR_TypeReserved = 37331
ERR_UnmanagedConstraintNotSatisfied = 37332

ERR_NextAvailable = 37333
ERR_CannotApplyOverloadResolutionPriorityToOverride = 37333
ERR_CannotApplyOverloadResolutionPriorityToMember = 37334

ERR_NextAvailable = 37335

'// WARNINGS BEGIN HERE
WRN_UseOfObsoleteSymbol2 = 40000
Expand Down Expand Up @@ -2083,5 +2086,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
FEATURE_InitOnlySettersUsage
FEATURE_CallerArgumentExpression
FEATURE_UnmanagedConstraint
FEATURE_OverloadResolutionPriority
End Enum
End Namespace
2 changes: 1 addition & 1 deletion src/Compilers/VisualBasic/Portable/Parser/ParserFeature.vb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Case Feature.UnmanagedConstraint
Return ERRID.FEATURE_UnmanagedConstraint
Case Feature.OverloadResolutionPriority
Return ERRID.ERR_None ' We are not reporting any feature diagnostics for 'Overload Resolution Priority' feature.
Return ERRID.FEATURE_OverloadResolutionPriority
Case Else
Throw ExceptionUtilities.UnexpectedValue(feature)
End Select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,6 @@ lReportErrorOnTwoTokens:

If Not CanHaveOverloadResolutionPriority Then
'Cannot use 'OverloadResolutionPriorityAttribute' on this member.
' PROTOTYPE(priority): Do we want to report an error? It will be a breaking change.
Return Nothing
End If

Expand Down Expand Up @@ -1750,6 +1749,19 @@ lReportErrorOnTwoTokens:
ElseIf VerifyObsoleteAttributeAppliedToMethod(arguments, AttributeDescription.DeprecatedAttribute) Then
ElseIf arguments.Attribute.IsTargetAttribute(AttributeDescription.ModuleInitializerAttribute) Then
diagnostics.Add(ERRID.WRN_AttributeNotSupportedInVB, arguments.AttributeSyntaxOpt.Location, AttributeDescription.ModuleInitializerAttribute.FullName)
ElseIf arguments.Attribute.IsTargetAttribute(AttributeDescription.OverloadResolutionPriorityAttribute) Then

If Not CanHaveOverloadResolutionPriority Then
diagnostics.Add(If(IsOverrides,
ERRID.ERR_CannotApplyOverloadResolutionPriorityToOverride,
ERRID.ERR_CannotApplyOverloadResolutionPriorityToMember),
arguments.AttributeSyntaxOpt.GetLocation())
Else
InternalSyntax.Parser.CheckFeatureAvailability(diagnostics,
arguments.AttributeSyntaxOpt.GetLocation(),
DirectCast(arguments.AttributeSyntaxOpt.SyntaxTree.Options, VisualBasicParseOptions).LanguageVersion,
InternalSyntax.Feature.OverloadResolutionPriority)
End If
Else
Dim methodImpl As MethodSymbol = If(Me.IsPartial, PartialImplementationPart, Me)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End Property

Public Overrides Function GetOverloadResolutionPriority() As Integer
Return 0 ' PROTOTYPE(Priority): Implement for real
Return 0 ' This symbol is used to produce a metadata artifact, it cannot be accessed by a user
End Function

Public Overrides ReadOnly Property IsOverridable As Boolean
Expand Down Expand Up @@ -1784,7 +1784,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End Property

Public Overrides Function GetOverloadResolutionPriority() As Integer
Return 0 ' PROTOTYPE(Priority): Follow up
Return 0 ' This symbol is used to produce a metadata artifact, it cannot be accessed by a user
End Function

Public Overrides ReadOnly Property IsOverridable As Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols

If Not CanHaveOverloadResolutionPriority Then
'Cannot use 'OverloadResolutionPriorityAttribute' on this member.
' PROTOTYPE(priority): Do we want to report an error? It will be a breaking change.
Return Nothing
End If

Expand Down Expand Up @@ -611,6 +610,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
_setMethod IsNot Nothing AndAlso DirectCast(_setMethod, SourcePropertyAccessorSymbol).HasDebuggerHiddenAttribute) Then
diagnostics.Add(ERRID.WRN_DebuggerHiddenIgnoredOnProperties, arguments.AttributeSyntaxOpt.GetLocation())
End If
Return
ElseIf arguments.Attribute.IsTargetAttribute(AttributeDescription.OverloadResolutionPriorityAttribute) Then

If Not CanHaveOverloadResolutionPriority Then
diagnostics.Add(If(IsOverrides,
ERRID.ERR_CannotApplyOverloadResolutionPriorityToOverride,
ERRID.ERR_CannotApplyOverloadResolutionPriorityToMember),
arguments.AttributeSyntaxOpt.GetLocation())
Else
InternalSyntax.Parser.CheckFeatureAvailability(diagnostics,
arguments.AttributeSyntaxOpt.GetLocation(),
DirectCast(arguments.AttributeSyntaxOpt.SyntaxTree.Options, VisualBasicParseOptions).LanguageVersion,
InternalSyntax.Feature.OverloadResolutionPriority)
End If

Return
End If
End If
Expand Down
9 changes: 9 additions & 0 deletions src/Compilers/VisualBasic/Portable/VBResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -5716,4 +5716,13 @@
<data name="ERR_TypeReserved" xml:space="preserve">
<value>The type name '{0}' is reserved to be used by the compiler.</value>
</data>
<data name="ERR_CannotApplyOverloadResolutionPriorityToOverride" xml:space="preserve">
<value>Cannot use 'OverloadResolutionPriorityAttribute' on an overriding member.</value>
</data>
<data name="ERR_CannotApplyOverloadResolutionPriorityToMember" xml:space="preserve">
<value>Cannot use 'OverloadResolutionPriorityAttribute' on this member.</value>
</data>
<data name="FEATURE_OverloadResolutionPriority" xml:space="preserve">
<value>overload resolution priority</value>
</data>
</root>
15 changes: 15 additions & 0 deletions src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/Compilers/VisualBasic/Portable/xlf/VBResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/Compilers/VisualBasic/Portable/xlf/VBResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/Compilers/VisualBasic/Portable/xlf/VBResources.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cde583e

Please sign in to comment.