-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Obsolete Attribute on Accessors #32571
Changes from 10 commits
38179e3
0af9dcf
3eb45f4
dc79ea5
376c8d5
272e44a
26d8a67
9c30cc3
da56be5
451c738
b2b7adf
4755eaa
c327ac2
dc32918
904f95d
d1e4cfd
921240d
4bc5bcb
a57e934
ad5175d
9a563e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,12 +55,7 @@ private static ThreeState GetObsoleteContextState(Symbol symbol, bool forceCompl | |
{ | ||
while ((object)symbol != null) | ||
{ | ||
// For property or event accessors, check the associated property or event instead. | ||
if (symbol.IsAccessor()) | ||
{ | ||
symbol = ((MethodSymbol)symbol).AssociatedSymbol; | ||
} | ||
else if (symbol.Kind == SymbolKind.Field) | ||
if (symbol.Kind == SymbolKind.Field) | ||
{ | ||
// If this is the backing field of an event, look at the event instead. | ||
var associatedSymbol = ((FieldSymbol)symbol).AssociatedSymbol; | ||
|
@@ -81,7 +76,15 @@ private static ThreeState GetObsoleteContextState(Symbol symbol, bool forceCompl | |
return state; | ||
} | ||
|
||
symbol = symbol.ContainingSymbol; | ||
// For property or event accessors, check the associated property or event next. | ||
if (symbol.IsAccessor()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This suppresses warnings/errors from the usage of an obsolete symbol in an accessor if the accessor is marked obsolete itself. We only really need to do this for properties, not for events, but it is simplest to treat them both equally, and it is arguable which way is most correct. For a similar reason, we change this for all C# versions, not just for C# 8 |
||
{ | ||
symbol = ((MethodSymbol)symbol).AssociatedSymbol; | ||
} | ||
else | ||
{ | ||
symbol = symbol.ContainingSymbol; | ||
} | ||
} | ||
|
||
return ThreeState.False; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1216,9 +1216,14 @@ private bool VerifyObsoleteAttributeAppliedToMethod( | |
{ | ||
if (this.IsAccessor()) | ||
{ | ||
// CS1667: Attribute '{0}' is not valid on property or event accessors. It is only valid on '{1}' declarations. | ||
AttributeUsageInfo attributeUsage = arguments.Attribute.AttributeClass.GetAttributeUsageInfo(); | ||
arguments.Diagnostics.Add(ErrorCode.ERR_AttributeNotOnAccessor, arguments.AttributeSyntaxOpt.Name.Location, description.FullName, attributeUsage.GetValidTargetsErrorArgument()); | ||
if (this is SourceEventAccessorSymbol) | ||
{ | ||
// CS1667: Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations. | ||
AttributeUsageInfo attributeUsage = arguments.Attribute.AttributeClass.GetAttributeUsageInfo(); | ||
arguments.Diagnostics.Add(ErrorCode.ERR_AttributeNotOnEventAccessor, arguments.AttributeSyntaxOpt.Name.Location, description.FullName, attributeUsage.GetValidTargetsErrorArgument()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Feels like we should check the language version in an |
||
|
||
MessageID.IDS_FeatureObsoleteOnPropertyAccessor.CheckFeatureAvailability(arguments.Diagnostics, arguments.AttributeSyntaxOpt.Location); | ||
} | ||
|
||
return true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how new error codes are picked. I am also not sure whether this should go with C# 1 errors, or C# 8, as it's just a different name/message for what is essentially an old error. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This number (in the C# 8.0 range) is fine.
In reply to: 265474149 [](ancestors = 265474149)