-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Store nullable attribute constructor params in a field: #33668
Conversation
- Add a derived nullable attribute symbol - Add a constructor symbol that allows assignment to a field - Generate the appropriate constructors for byte and byte[] versions of the attribute - Add tests
_constructors = getConstructors(compilation, this, diagnostics); | ||
} | ||
else | ||
if (generateDefaultConstructors) |
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 hate this. Any ideas on a better approach most welcome.
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.
Perhaps replace the _constructors
field with an abstract Constructors
property, and have two derived types, one that returns a single constructor with no parameters.
In reply to: 260050571 [](ancestors = 260050571)
@dotnet/roslyn-compiler for review please. |
{ | ||
private readonly ImmutableArray<FieldSymbol> _fields; | ||
|
||
private readonly TypeSymbolWithAnnotations _byteType; |
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.
TypeSymbolWithAnnotations [](start = 25, length = 25)
Can be stored as TypeSymbol
.
|
||
internal sealed class SynthesizedEmbeddedAttributeConstructorWithBodySymbol : SynthesizedInstanceConstructor | ||
{ | ||
ImmutableArray<ParameterSymbol> _parameters; |
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.
ImmutableArray [](start = 12, length = 14)
private readonly
{ | ||
ImmutableArray<ParameterSymbol> _parameters; | ||
|
||
readonly Action<SyntheticBoundNodeFactory, ArrayBuilder<BoundStatement>, ImmutableArray<ParameterSymbol>> _getConstructorBody; |
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.
readonly [](start = 12, length = 8)
private
); | ||
} | ||
|
||
internal sealed class SynthesizedEmbeddedAttributeConstructorWithBodySymbol : SynthesizedInstanceConstructor |
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.
internal [](start = 8, length = 8)
private
} | ||
|
||
[Fact] | ||
public void Field_Contains_ConstuctorArugments_SingleByteConstructor() |
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.
Constuctor [](start = 35, length = 10)
Typo, here and test below.
@@ -1686,6 +1689,107 @@ static void F(B<A<(object?, (object, object?), object, object?, object, object?, | |||
type.GetMember<PropertySymbol>("Property").ToTestDisplayString()); | |||
} | |||
|
|||
[Fact] | |||
public void Field_Exists() |
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.
Field_ [](start = 20, length = 6)
The test names are a little confusing since it's not clear what "Field" refers to (at least it won't be clear outside of this PR). Perhaps name these tests "NullableAttribute_" or "NullableAttributeField_" as approriate.
namespace Microsoft.CodeAnalysis.CSharp.Symbols | ||
{ | ||
|
||
internal class SynthesizedEmbeddedNullableAttributeSymbol : SynthesizedEmbeddedAttributeSymbol |
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.
class [](start = 13, length = 5)
sealed
@@ -305,42 +303,36 @@ private void CreateEmbeddedAttributeItselfIfNeeded(DiagnosticBag diagnostics) | |||
private void CreateEmbeddedAttributeIfNeeded( | |||
ref SynthesizedEmbeddedAttributeSymbol symbol, | |||
DiagnosticBag diagnostics, | |||
AttributeDescription description, | |||
Func<CSharpCompilation, NamedTypeSymbol, DiagnosticBag, ImmutableArray<MethodSymbol>> getConstructors = null) | |||
AttributeDescription description) | |||
{ | |||
if ((object)symbol == null) |
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.
symbol is null
#Resolved
new SynthesizedEmbeddedAttributeConstructorSymbol( | ||
containingType, | ||
m => ImmutableArray.Create(SynthesizedParameterSymbol.Create(m, byteArray, 0, RefKind.None)))); | ||
if ((object)symbol == null) |
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.
symbol is null
#Resolved
private readonly ModuleSymbol _module; | ||
|
||
protected ImmutableArray<MethodSymbol> _constructors; |
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.
protected
values should be PascalCased and not _
prefixed.
new SynthesizedFieldSymbol( | ||
this, | ||
byteArrayType.TypeSymbol, | ||
"nullableFlags", |
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.
Given this is public
it should be PascalCased
Done with review pass (iteration 1) |
- Split SynthesizedEmbeddedAttribute into a base class and implementation - Rename nullableFlags to NullableFlags - Rename tests
|
||
/// <summary> | ||
/// When implemented by a more derived type, gets a list of constructors to synthesize for the attribute | ||
/// </summary> |
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.
Blank line below.
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.
/// 4) It has System.Runtime.CompilerServices.CompilerGeneratedAttribute | ||
/// 5) It has a parameter-less constructor | ||
/// </summary> | ||
internal abstract class SynthesizedEmbeddedAttributeSymbolBase : NamedTypeSymbol |
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.
SynthesizedEmbeddedAttributeSymbolBase [](start = 28, length = 38)
Consider leaving this type in SynthesizedEmbeddedAttributeSymbol.cs
, along with the derived type, so the changes in this PR are clear.
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.
Done.
Closes #30143