-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Ensure custom attributes bag of a parameter backing field is properly initialized during "completion" of a primary constructor. #80424
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3118,7 +3118,7 @@ public class A : System.Attribute | |
| [field: A] | ||
| int P1) | ||
| { | ||
| int M1() => P1; | ||
| [A] int M1() => P1; | ||
| } | ||
|
|
||
| [System.AttributeUsage(System.AttributeTargets.Field, AllowMultiple = true) ] | ||
|
|
@@ -3133,7 +3133,12 @@ public class C : System.Attribute | |
| int M1() => P1; | ||
| } | ||
| "; | ||
| var comp = CreateCompilation(source); | ||
| var comp = CreateCompilation(source, parseOptions: TestOptions.RegularDefault.WithFeature("run-nullable-analysis", "never")); | ||
| var test1 = comp.GetTypeByMetadataName("Test1"); | ||
| var ctor = test1.InstanceConstructors.Where(c => !c.IsDefaultValueTypeConstructor()).Single(); | ||
|
|
||
| ctor.GetAttributes(); | ||
|
Member
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. Consider asserting at least number of the attributes returned by this call.
Contributor
Author
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 is not interesting. We are requesting the attributes to get symbol into a certain state. |
||
|
|
||
| comp.VerifyDiagnostics( | ||
| // (8,6): warning CS0657: 'field' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'param'. All attributes in this block will be ignored. | ||
| // [field: A] | ||
|
|
@@ -3143,7 +3148,12 @@ public class C : System.Attribute | |
| Diagnostic(ErrorCode.ERR_AttributeOnBadSymbolType, "C").WithArguments("C", "field").WithLocation(20, 6) | ||
| ); | ||
|
|
||
| Assert.Empty(comp.GetTypeByMetadataName("Test1").InstanceConstructors.Where(c => !c.IsDefaultValueTypeConstructor()).Single().Parameters[0].GetAttributes()); | ||
| Assert.Empty(ctor.Parameters[0].GetAttributes()); | ||
|
|
||
| var field = test1.GetMembers().OfType<FieldSymbol>().Single(); | ||
| Assert.Equal(ObsoleteAttributeKind.None, field.ObsoleteKind); | ||
| Assert.Empty(field.GetAttributes()); | ||
|
|
||
| Assert.Equal(1, comp.GetTypeByMetadataName("Test2").InstanceConstructors.Where(c => !c.IsDefaultValueTypeConstructor()).Single().Parameters[0].GetAttributes().Count()); | ||
| } | ||
|
|
||
|
|
||
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.
Is
.WithFeature("run-nullable-analysis", "never")somehow important for the test?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.
Yes, by default debug build performs nullable analysis even if one is not enabled in source. That requests attributes from symbols. We want to control when attributes are requested and from what symbols.