Support more well-known attributes in local functions#41299
Conversation
| // Note that this doesn't affect BaseMethodWrapperSymbol for example because the implementation has no locals. | ||
| public sealed override bool AreLocalsZeroed => !(BaseMethod is SourceMethodSymbol sourceMethod) || sourceMethod.AreLocalsZeroed; | ||
|
|
||
| internal override bool RequiresSecurityObject => InheritsBaseMethodAttributes && BaseMethod.RequiresSecurityObject; |
There was a problem hiding this comment.
override [](start = 17, length = 8)
sealed for each override. #Closed
| line: 13 | ||
| "; | ||
|
|
||
| var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.RegularPreview); |
There was a problem hiding this comment.
CreateCompilationWithMscorlib45 [](start = 30, length = 31)
CreateCompilation? #Closed
|
|
||
| var compilation = CreateCompilationWithMscorlib45( | ||
| source, | ||
| references: new MetadataReference[] { SystemRef }, |
There was a problem hiding this comment.
CreateCompilation(source, ... here and in other added tests? #Closed
| }"; | ||
|
|
||
| var expected = @" | ||
| name: LocalFunctionCaller |
There was a problem hiding this comment.
LocalFunctionCaller [](start = 6, length = 19)
Should this report "local1" instead?
This is consistent with the name used when calling a member method with [CallerMemberName] from a local function. #Closed
| } | ||
| } | ||
| "; | ||
| var compilation = CreateCompilationWithMscorlib40(source, options: TestOptions.ReleaseDll, parseOptions: TestOptions.RegularPreview); |
There was a problem hiding this comment.
CreateCompilationWithMscorlib40 [](start = 30, length = 31)
CreateCompilation? #Resolved
| } | ||
|
|
||
| [Fact] | ||
| public void LocalFunctionParamsArray_ParamArrayAttribute() |
There was a problem hiding this comment.
ParamArrayAttribute [](start = 45, length = 19)
There is no ParamArrayAttribute in the test. If that's intentional, consider removing _ParamArrayAttribute from the test name. #Resolved
| get { return ImmutableArray<CustomModifier>.Empty; } | ||
| } | ||
|
|
||
| internal override MarshalPseudoCustomAttributeData MarshallingInformation |
There was a problem hiding this comment.
internal override MarshalPseudoCustomAttributeData MarshallingInformation [](start = 12, length = 73)
It is not clear what motivated this change. #Closed
There was a problem hiding this comment.
Because I deleted the implementation in SynthesizedParameterSymbolBase, it was necessary to provide an implementation in each subtype.
In reply to: 373183931 [](ancestors = 373183931)
| p.Name, | ||
| attributes: inheritAttributes ? p.GetAttributes() : default, | ||
| hasEnumeratorCancellationAttribute: inheritAttributes && p.IsSourceParameterWithEnumeratorCancellationAttribute())); | ||
| p.RefCustomModifiers, |
There was a problem hiding this comment.
p.RefCustomModifiers [](start = 20, length = 20)
Should these be substituted? It looks like we didn't pass these before. Do we have a test with a scenario where this change makes a difference? #Closed
| { | ||
| Debug.Assert(!refCustomModifiers.IsDefault); | ||
| Debug.Assert(!attributes.IsDefault); | ||
| Debug.Assert(!refCustomModifiers.IsEmpty || baseParameterForAttributes is object); |
There was a problem hiding this comment.
!refCustomModifiers.IsEmpty || baseParameterForAttributes is object [](start = 25, length = 67)
It is not obvious why is this the right thing to assert #Closed
There was a problem hiding this comment.
If this condition is false, it means there was no good reason to create this as a SynthesizedComplexParameterSymbol instead of a SynthesizedParameterSymbol.
In reply to: 373192152 [](ancestors = 373192152)
| oldParam.RefKind, | ||
| oldParam.Name, | ||
| oldParam.RefCustomModifiers, | ||
| (oldParam as SynthesizedComplexParameterSymbol)?.BaseParameterForAttributes)); |
There was a problem hiding this comment.
(oldParam as SynthesizedComplexParameterSymbol) [](start = 20, length = 47)
Are there scenarios when this is not null? Do we have a test "backing" this change? #Closed
There was a problem hiding this comment.
I don't think any test is affected by this change. This is used for SynthesizedEntryPointSymbol, SynthesizedImplementationMethod, and SynthesizedSealedPropertyAccessor. Actually, this seems like a behavior change where for example a synthesized sealed accessor may start to contain attributes from a base accessor from source, when it didn't before. So perhaps the right thing to do here is to just revert the change.
In reply to: 373194840 [](ancestors = 373194840)
There was a problem hiding this comment.
If for all scenarios that can happen today oldParam is never a SynthesizedComplexParameterSymbol, I would add an assert to confirm this fact and pass null.
In reply to: 373204933 [](ancestors = 373204933,373194840)
| case DebugInfoInjector { Previous: var previous } injector: | ||
| var newPrevious = RemoveDynamicAnalysisInjectors(previous); | ||
| return (object)newPrevious != previous ? new DebugInfoInjector(newPrevious) : injector; | ||
| if ((object)newPrevious == Instrumenter.NoOp) |
There was a problem hiding this comment.
(object)newPrevious == Instrumenter.NoOp [](start = 24, length = 40)
I think it would be better to check if (object)newPrevious == previous first #Closed
| Console.WriteLine(""name: "" + callerName); | ||
| } | ||
|
|
||
| log(); |
There was a problem hiding this comment.
log(); [](start = 12, length = 6)
Consider also testing scenario with nesting into a lambda #Closed
| Assert.Empty(localFn1.GetReturnTypeAttributes()); | ||
|
|
||
| var param = localFn1.Parameters.Single(); | ||
| Assert.Empty(param.GetAttributes()); |
There was a problem hiding this comment.
Assert.Empty(param.GetAttributes()); [](start = 16, length = 36)
Is this intentional? Did we explicitly decide to not synthesize the attribute? #Closed
There was a problem hiding this comment.
|
Done with review pass (iteration 6) #Closed |
| private readonly ImmutableArray<CSharpAttributeData> _attributes; | ||
|
|
||
| // The parameter containing attributes to inherit into this synthesized parameter, if any. | ||
| internal SourceComplexParameterSymbol? BaseParameterForAttributes { get; } |
There was a problem hiding this comment.
internal [](start = 8, length = 8)
Could this be a private readonly field? #Resolved
Related to #38801