Skip to content

Commit b3ee966

Browse files
author
Julien Couvreur
committed
Extensions: propagate return-targeted and local function parameter attributes
1 parent fb066d0 commit b3ee966

File tree

14 files changed

+424
-29
lines changed

14 files changed

+424
-29
lines changed

src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ private ImmutableArray<ParameterSymbol> MakeParameters()
129129
p.ExplicitDefaultConstantValue,
130130
// the synthesized parameter doesn't need to have the same ref custom modifiers as the base
131131
refCustomModifiers: default,
132-
inheritAttributes ? p as SourceComplexParameterSymbolBase : null));
132+
baseParameterForAttributes: inheritAttributes ? p : null));
133133
}
134+
134135
var extraSynthed = ExtraSynthesizedRefParameters;
135136
if (!extraSynthed.IsDefaultOrEmpty)
136137
{
@@ -139,6 +140,7 @@ private ImmutableArray<ParameterSymbol> MakeParameters()
139140
builder.Add(SynthesizedParameterSymbol.Create(this, this.TypeMap.SubstituteType(extra), ordinal++, RefKind.Ref));
140141
}
141142
}
143+
142144
return builder.ToImmutableAndFree();
143145
}
144146

src/Compilers/CSharp/Portable/Symbols/Extensions/RewrittenMethodSymbol.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using System.Collections.Immutable;
66
using System.Diagnostics;
7-
using Roslyn.Utilities;
87

98
namespace Microsoft.CodeAnalysis.CSharp.Symbols
109
{
@@ -87,6 +86,11 @@ public sealed override ImmutableArray<CSharpAttributeData> GetAttributes()
8786
return _originalMethod.GetAttributes();
8887
}
8988

89+
public override ImmutableArray<CSharpAttributeData> GetReturnTypeAttributes()
90+
{
91+
return _originalMethod.GetReturnTypeAttributes();
92+
}
93+
9094
internal sealed override UseSiteInfo<AssemblySymbol> GetUseSiteInfo()
9195
{
9296
return _originalMethod.GetUseSiteInfo();

src/Compilers/CSharp/Portable/Symbols/FunctionPointers/FunctionPointerParameterSymbol.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ internal int MethodHashCode()
8181
internal override bool IsMetadataIn => RefKind is RefKind.In or RefKind.RefReadOnlyParameter;
8282
internal override bool IsMetadataOut => RefKind == RefKind.Out;
8383
internal override ConstantValue? ExplicitDefaultConstantValue => null;
84+
internal override ConstantValue DefaultValueFromAttributes => ConstantValue.NotAvailable;
8485
internal override bool IsIDispatchConstant => false;
8586
internal override bool IsIUnknownConstant => false;
8687
internal override bool IsCallerFilePath => false;

src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEParameterSymbol.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@ internal override ConstantValue? ExplicitDefaultConstantValue
569569
}
570570
}
571571

572+
internal override ConstantValue DefaultValueFromAttributes => ConstantValue.NotAvailable;
573+
572574
private ConstantValue? GetDefaultDecimalOrDateTimeValue()
573575
{
574576
Debug.Assert(!_handle.IsNil);

src/Compilers/CSharp/Portable/Symbols/ParameterSymbol.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,13 @@ public object? ExplicitDefaultValue
254254
/// </remarks>
255255
internal abstract ConstantValue? ExplicitDefaultConstantValue { get; }
256256

257+
/// <summary>
258+
/// Returns the default value from attributes on the parameter,
259+
/// for symbols from source or derived from source symbols.
260+
/// Returns <see cref="ConstantValue.NotAvailable"/> when not applicable.
261+
/// </summary>
262+
internal abstract ConstantValue DefaultValueFromAttributes { get; }
263+
257264
/// <summary>
258265
/// Gets the kind of this symbol.
259266
/// </summary>

src/Compilers/CSharp/Portable/Symbols/SignatureOnlyParameterSymbol.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ internal override ScopedKind EffectiveScope
7878

7979
internal override ConstantValue ExplicitDefaultConstantValue { get { throw ExceptionUtilities.Unreachable(); } }
8080

81+
internal override ConstantValue DefaultValueFromAttributes { get { throw ExceptionUtilities.Unreachable(); } }
82+
8183
internal override bool IsIDispatchConstant { get { throw ExceptionUtilities.Unreachable(); } }
8284

8385
internal override bool IsIUnknownConstant { get { throw ExceptionUtilities.Unreachable(); } }

src/Compilers/CSharp/Portable/Symbols/Source/SourceParameterSymbolBase.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public sealed override AssemblySymbol ContainingAssembly
6464
get { return _containingSymbol.ContainingAssembly; }
6565
}
6666

67-
internal abstract ConstantValue DefaultValueFromAttributes { get; }
68-
6967
internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
7068
{
7169
base.AddSynthesizedAttributes(moduleBuilder, ref attributes);

src/Compilers/CSharp/Portable/Symbols/Source/ThisParameterSymbol.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ internal sealed override ConstantValue? ExplicitDefaultConstantValue
2525
get { return null; }
2626
}
2727

28+
internal override ConstantValue DefaultValueFromAttributes
29+
{
30+
get { return ConstantValue.NotAvailable; }
31+
}
32+
2833
internal sealed override bool IsMetadataOptional
2934
{
3035
get { return false; }

src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedIntrinsicOperatorSymbol.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ string name
476476

477477
internal override bool IsMetadataOut => RefKind == RefKind.Out;
478478

479+
internal override ConstantValue DefaultValueFromAttributes => ConstantValue.NotAvailable;
480+
479481
public override bool Equals(Symbol obj, TypeCompareKind compareKind)
480482
{
481483
if (obj == (object)this)

src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedParameterSymbol.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ internal override ConstantValue? ExplicitDefaultConstantValue
8585
get { return null; }
8686
}
8787

88-
internal virtual ConstantValue? DefaultValueFromAttributes => null;
89-
9088
internal override bool IsIDispatchConstant
9189
{
9290
get { throw ExceptionUtilities.Unreachable(); }
@@ -254,6 +252,8 @@ private SynthesizedParameterSymbol(
254252

255253
internal sealed override bool IsMetadataOut => RefKind == RefKind.Out;
256254

255+
internal override ConstantValue DefaultValueFromAttributes => ConstantValue.NotAvailable;
256+
257257
public static ParameterSymbol Create(
258258
Symbol? container,
259259
TypeWithAnnotations type,
@@ -263,7 +263,7 @@ public static ParameterSymbol Create(
263263
ScopedKind scope = ScopedKind.None,
264264
ConstantValue? defaultValue = null,
265265
ImmutableArray<CustomModifier> refCustomModifiers = default,
266-
SourceComplexParameterSymbolBase? baseParameterForAttributes = null,
266+
ParameterSymbol? baseParameterForAttributes = null,
267267
bool isParams = false,
268268
bool hasUnscopedRefAttribute = false)
269269
{
@@ -340,7 +340,7 @@ internal sealed class SynthesizedComplexParameterSymbol : SynthesizedParameterSy
340340
private readonly ImmutableArray<CustomModifier> _refCustomModifiers;
341341

342342
// The parameter containing attributes to inherit into this synthesized parameter, if any.
343-
private readonly SourceComplexParameterSymbolBase? _baseParameterForAttributes;
343+
private readonly ParameterSymbol? _baseParameterForAttributes;
344344
private readonly ConstantValue? _defaultValue;
345345
private readonly bool _isParams;
346346
private readonly bool _hasUnscopedRefAttribute;
@@ -354,14 +354,15 @@ public SynthesizedComplexParameterSymbol(
354354
ConstantValue? defaultValue,
355355
string name,
356356
ImmutableArray<CustomModifier> refCustomModifiers,
357-
SourceComplexParameterSymbolBase? baseParameterForAttributes,
357+
ParameterSymbol? baseParameterForAttributes,
358358
bool isParams,
359359
bool hasUnscopedRefAttribute)
360360
: base(container, type, ordinal, refKind, scope, name)
361361
{
362362
Debug.Assert(!refCustomModifiers.IsDefault);
363363
Debug.Assert(isParams || !refCustomModifiers.IsEmpty || baseParameterForAttributes is object || defaultValue is not null || hasUnscopedRefAttribute);
364364
Debug.Assert(baseParameterForAttributes is null || baseParameterForAttributes.ExplicitDefaultConstantValue == defaultValue);
365+
Debug.Assert(baseParameterForAttributes is null || baseParameterForAttributes.RefKind == refKind);
365366

366367
_refCustomModifiers = refCustomModifiers;
367368
_baseParameterForAttributes = baseParameterForAttributes;
@@ -407,13 +408,13 @@ internal override bool IsCallerMemberName
407408
get => _baseParameterForAttributes?.IsCallerMemberName ?? false;
408409
}
409410

410-
internal override bool IsMetadataIn => RefKind is RefKind.In or RefKind.RefReadOnlyParameter || _baseParameterForAttributes?.GetDecodedWellKnownAttributeData()?.HasInAttribute == true;
411+
internal override bool IsMetadataIn => RefKind is RefKind.In or RefKind.RefReadOnlyParameter || _baseParameterForAttributes?.IsMetadataIn == true;
411412

412-
internal override bool IsMetadataOut => RefKind == RefKind.Out || _baseParameterForAttributes?.GetDecodedWellKnownAttributeData()?.HasOutAttribute == true;
413+
internal override bool IsMetadataOut => RefKind == RefKind.Out || _baseParameterForAttributes?.IsMetadataOut == true;
413414

414-
internal override ConstantValue? ExplicitDefaultConstantValue => _baseParameterForAttributes?.ExplicitDefaultConstantValue ?? _defaultValue;
415+
internal override ConstantValue? ExplicitDefaultConstantValue => _defaultValue;
415416

416-
internal override ConstantValue? DefaultValueFromAttributes => _baseParameterForAttributes?.DefaultValueFromAttributes;
417+
internal override ConstantValue DefaultValueFromAttributes => _baseParameterForAttributes?.DefaultValueFromAttributes ?? ConstantValue.NotAvailable;
417418

418419
internal override FlowAnalysisAnnotations FlowAnalysisAnnotations
419420
{

0 commit comments

Comments
 (0)