-
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
Add NullableContextAttribute #36152
Merged
+3,232
−770
Merged
Add NullableContextAttribute #36152
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
dd4779e
Add NullableContextAttribute
cston cf0b03c
Fix tests
cston 89766b6
Fix tests
cston f5db1fb
Fix tests
cston 35b4a24
More tests
cston 6eda1db
PR feedback
cston e9069c9
PR feedback
cston b92ae07
Fix test
cston 6db6043
Report error for explicit use of attributes
cston b5a3b73
Fix formatting
cston 6acd5ca
PR feedback
cston 14a9376
Add NullablePublicOnlyAttribute.IncludesInternals field
cston 1858ffe
Move check for NullablePublicOnlyAttribute
cston f610924
PR feedback
cston 510fcfb
Invoke GetNullableContextValue lazily
cston a40a302
PR feedback
cston f83fd06
Cache full nullable context value
cston 5ed7323
Delegate to containing symbol for accessibility
cston b64cf78
PR feedback
cston 2dfe52a
PR feedback
cston b238d9c
Use GetInterfacesToEmit
cston 12648ee
Move handling of dynamic and tuple attributes
cston b40be6d
Misc.
cston 2ca9546
Fix typo
cston f28acab
Fix test
cston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Report error for explicit use of attributes
commit 6db60433db56bc0c3f644e82d627b464932b2415
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,54 @@ public sealed class NullableContextAttribute : Attribute | |
Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "F").WithArguments("System.Runtime.CompilerServices.NullableContextAttribute", ".ctor").WithLocation(3, 19)); | ||
} | ||
|
||
[Fact] | ||
public void ExplicitAttribute_ReferencedInSource() | ||
{ | ||
var sourceAttribute = | ||
@"namespace System.Runtime.CompilerServices | ||
{ | ||
internal class NullableContextAttribute : System.Attribute | ||
{ | ||
internal NullableContextAttribute(byte b) { } | ||
} | ||
}"; | ||
var source = | ||
@"#pragma warning disable 169 | ||
using System.Runtime.CompilerServices; | ||
[assembly: NullableContext(0)] | ||
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. Should we get an error for this attribute? #Closed 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. |
||
[module: NullableContext(0)] | ||
[NullableContext(0)] | ||
class Program | ||
{ | ||
[NullableContext(0)]object F; | ||
[NullableContext(0)]static object M1() => throw null; | ||
[return: NullableContext(0)]static object M2() => throw null; | ||
static void M3([NullableContext(0)]object arg) { } | ||
}"; | ||
|
||
// C#7 | ||
var comp = CreateCompilation(new[] { sourceAttribute, source }, parseOptions: TestOptions.Regular7); | ||
verifyDiagnostics(comp); | ||
|
||
// C#8 | ||
comp = CreateCompilation(new[] { sourceAttribute, source }); | ||
verifyDiagnostics(comp); | ||
|
||
static void verifyDiagnostics(CSharpCompilation comp) | ||
{ | ||
comp.VerifyDiagnostics( | ||
// (4,10): error CS8335: Do not use 'System.Runtime.CompilerServices.NullableContextAttribute'. This is reserved for compiler usage. | ||
// [module: NullableContext(0)] | ||
Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, "NullableContext(0)").WithArguments("System.Runtime.CompilerServices.NullableContextAttribute").WithLocation(4, 10), | ||
// (5,2): error CS8335: Do not use 'System.Runtime.CompilerServices.NullableContextAttribute'. This is reserved for compiler usage. | ||
// [NullableContext(0)] | ||
Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, "NullableContext(0)").WithArguments("System.Runtime.CompilerServices.NullableContextAttribute").WithLocation(5, 2), | ||
// (9,6): error CS8335: Do not use 'System.Runtime.CompilerServices.NullableContextAttribute'. This is reserved for compiler usage. | ||
// [NullableContext(0)]static object M1() => throw null; | ||
Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, "NullableContext(0)").WithArguments("System.Runtime.CompilerServices.NullableContextAttribute").WithLocation(9, 6)); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ExplicitAttribute_WithNullableContext() | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Isn't this attribute a module level attribute? I do not think we should duplicate what the attribute usage attribute is for. #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 check should have been on
SourceModuleSymbol
. Moved.In reply to: 296890713 [](ancestors = 296890713)