Skip to content

Commit

Permalink
Adjust public API based on API review feedback (#71940)
Browse files Browse the repository at this point in the history
Closes #71816.
  • Loading branch information
AlekseyTs authored Feb 5, 2024
1 parent 897fd49 commit 1c5c7e2
Show file tree
Hide file tree
Showing 43 changed files with 230 additions and 168 deletions.
8 changes: 4 additions & 4 deletions src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4794,8 +4794,8 @@ private SignatureOnlyMethodSymbol GetInlineArrayAccessEquivalentSignatureMethod(
ImmutableArray.Create<ParameterSymbol>(new SignatureOnlyParameterSymbol(
TypeWithAnnotations.Create(elementAccess.Expression.Type),
ImmutableArray<CustomModifier>.Empty,
isParamArray: false,
isParamCollection: false,
isParamsArray: false,
isParamsCollection: false,
parameterRefKind
)),
resultRefKind,
Expand Down Expand Up @@ -4834,8 +4834,8 @@ private SignatureOnlyMethodSymbol GetInlineArrayConversionEquivalentSignatureMet
ImmutableArray.Create<ParameterSymbol>(new SignatureOnlyParameterSymbol(
TypeWithAnnotations.Create(inlineArray.Type),
ImmutableArray<CustomModifier>.Empty,
isParamArray: false,
isParamCollection: false,
isParamsArray: false,
isParamsCollection: false,
parameterRefKind
)),
RefKind.None,
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Crefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ private ImmutableArray<ParameterSymbol> BindCrefParameters(BaseCrefParameterList
Debug.Assert(parameterListSyntax.Parent is object);
TypeSymbol type = BindCrefParameterOrReturnType(parameter.Type, (MemberCrefSyntax)parameterListSyntax.Parent, diagnostics);

parameterBuilder.Add(new SignatureOnlyParameterSymbol(TypeWithAnnotations.Create(type), ImmutableArray<CustomModifier>.Empty, isParamArray: false, isParamCollection: false, refKind: refKind));
parameterBuilder.Add(new SignatureOnlyParameterSymbol(TypeWithAnnotations.Create(type), ImmutableArray<CustomModifier>.Empty, isParamsArray: false, isParamsCollection: false, refKind: refKind));
}

return parameterBuilder.ToImmutableAndFree();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public override Conversion GetMethodGroupDelegateConversion(BoundMethodGroup sou
if (methodSymbol.OriginalDefinition is SynthesizedDelegateInvokeMethod invoke)
{
// If synthesizing a delegate with `params` array, check that `ParamArrayAttribute` is available.
if (invoke.Parameters is [.., { IsParamArray: true }])
if (invoke.Parameters is [.., { IsParamsArray: true }])
{
Binder.AddUseSiteDiagnosticForSynthesizedAttribute(
Compilation,
Expand Down Expand Up @@ -413,7 +413,7 @@ public static void GetDelegateOrFunctionPointerArguments(SyntaxNode syntax, Anal
// which will cause some error to be reported. That's sufficient (i.e. no need to specifically report its absence here).
parameter = new SignatureOnlyParameterSymbol(
TypeWithAnnotations.Create(compilation.GetSpecialType(SpecialType.System_Object), customModifiers: parameter.TypeWithAnnotations.CustomModifiers), parameter.RefCustomModifiers,
isParamArray: parameter.IsParamArray, isParamCollection: parameter.IsParamCollection, parameter.RefKind);
isParamsArray: parameter.IsParamsArray, isParamsCollection: parameter.IsParamsCollection, parameter.RefKind);
}

analyzedArguments.Arguments.Add(new BoundParameter(syntax, parameter) { WasCompilerGenerated = true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ public static bool IsValidParams(Binder binder, Symbol member)
}

ParameterSymbol final = member.GetParameters().Last();
if ((final.IsParamArray && final.Type.IsSZArray()) || (final.IsParamCollection && !final.Type.IsSZArray()))
if ((final.IsParamsArray && final.Type.IsSZArray()) || (final.IsParamsCollection && !final.Type.IsSZArray()))
{
return TryInferParamsCollectionIterationType(binder, final.OriginalDefinition.Type, out _);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1328,8 +1328,8 @@ private static void ReportBadArgumentError(
SignatureOnlyParameterSymbol displayArg = new SignatureOnlyParameterSymbol(
TypeWithAnnotations.Create(argType),
ImmutableArray<CustomModifier>.Empty,
isParamArray: false,
isParamCollection: false,
isParamsArray: false,
isParamsCollection: false,
refKind: refArg);

SymbolDistinguisher distinguisher = new SymbolDistinguisher(binder.Compilation, displayArg, unwrapIfParamsCollection(badArg, parameter, isLastParameter));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ otherType.DelegateInvokeMethod is { } otherInvokeMethod &&
invokeMethod.Parameters.SequenceEqual(otherInvokeMethod.Parameters,
(x, y) => isCorrespondingType(x.TypeWithAnnotations, y.TypeWithAnnotations) &&
x.ExplicitDefaultConstantValue == y.ExplicitDefaultConstantValue &&
x.IsParamArray == y.IsParamArray &&
x.IsParamCollection == y.IsParamCollection) &&
x.IsParamsArray == y.IsParamsArray &&
x.IsParamsCollection == y.IsParamsCollection) &&
isCorrespondingType(invokeMethod.ReturnTypeWithAnnotations, otherInvokeMethod.ReturnTypeWithAnnotations);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ public override BoundNode VisitLambda(BoundLambda node)

if (delegateType?.IsAnonymousType == true && delegateType.ContainingModule == _compilation.SourceModule &&
delegateType.DelegateInvokeMethod() is MethodSymbol delegateInvoke &&
delegateInvoke.Parameters.Any(static (p) => p.IsParamCollection))
delegateInvoke.Parameters.Any(static (p) => p.IsParamsCollection))
{
Location location;
if (node.Symbol.Parameters.LastOrDefault(static (p) => p.IsParamCollection) is { } parameter)
if (node.Symbol.Parameters.LastOrDefault(static (p) => p.IsParamsCollection) is { } parameter)
{
location = ParameterHelpers.GetParameterLocation(parameter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ private void EnsureParamCollectionAttributeExists(SyntaxNode node, TypeSymbol de

if (delegateType.IsAnonymousType && delegateType.ContainingModule == _compilation.SourceModule &&
delegateType.DelegateInvokeMethod() is MethodSymbol delegateInvoke &&
delegateInvoke.Parameters.Any(static (p) => p.IsParamCollection))
delegateInvoke.Parameters.Any(static (p) => p.IsParamsCollection))
{
_factory.ModuleBuilderOpt.EnsureParamCollectionAttributeExists(_diagnostics, node.Location);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ public override void VisitParameter(IParameterSymbol symbol)
AddSpace();
}

if (symbol.IsParams || symbol.IsParamCollection)
if (symbol.IsParams)
{
AddKeyword(SyntaxKind.ParamsKeyword);
AddSpace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ internal CSharpSyntaxNode GetAttributeArgumentSyntax(int parameterIndex)
// -1 signifies optional parameter whose default argument is used, or
// an empty params array.
Debug.Assert(this.AttributeConstructor.Parameters[parameterIndex].IsOptional ||
this.AttributeConstructor.Parameters[parameterIndex].IsParamArray);
this.AttributeConstructor.Parameters[parameterIndex].IsParamsArray);
return attributeSyntax.Name;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ internal int MethodHashCode()
public override ImmutableArray<Location> Locations => ImmutableArray<Location>.Empty;
public override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences => ImmutableArray<SyntaxReference>.Empty;
public override bool IsDiscard => false;
public override bool IsParamArray => false;
public override bool IsParamCollection => false;
public override bool IsParamsArray => false;
public override bool IsParamsCollection => false;
public override bool IsImplicitlyDeclared => true;
internal override MarshalPseudoCustomAttributeData? MarshallingInformation => null;
internal override bool IsMetadataOptional => false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,15 +989,15 @@ internal override UnmanagedType MarshallingType
}
}

public override bool IsParamArray
public override bool IsParamsArray
{
get
{
return (GetIsParamsValues() & IsParamsValues.Array) != 0;
}
}

public override bool IsParamCollection
public override bool IsParamsCollection
{
get
{
Expand Down
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Portable/Symbols/ParameterSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ internal bool IsMarshalAsObject
/// Note: it is possible for any parameter to have the [ParamArray] attribute (for instance, in IL),
/// even if it is not the last parameter. So check for that.
/// </summary>
public abstract bool IsParamArray { get; }
public abstract bool IsParamsArray { get; }

/// <summary>
/// Returns true if the parameter was declared as a parameter collection.
/// Note: it is possible for any parameter to have the [ParamCollection] attribute (for instance, in IL),
/// even if it is not the last parameter. So check for that.
/// </summary>
public abstract bool IsParamCollection { get; }
public abstract bool IsParamsCollection { get; }

internal bool IsParams => IsParamArray || IsParamCollection;
internal bool IsParams => IsParamsArray || IsParamsCollection;

/// <summary>
/// Returns true if the parameter is semantically optional.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ IParameterSymbol IParameterSymbol.OriginalDefinition

bool IParameterSymbol.IsDiscard => _underlying.IsDiscard;

bool IParameterSymbol.IsParams => _underlying.IsParamArray;
bool IParameterSymbol.IsParams => _underlying.IsParams;

bool IParameterSymbol.IsParamCollection => _underlying.IsParamCollection;
bool IParameterSymbol.IsParamsArray => _underlying.IsParamsArray;

bool IParameterSymbol.IsParamsCollection => _underlying.IsParamsCollection;

bool IParameterSymbol.IsOptional => _underlying.IsOptional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,8 @@ IEqualityComparer<MethodSymbol> retargetedMethodComparer
static ParameterSymbol (param, translator) => new SignatureOnlyParameterSymbol(
translator.Retarget(param.TypeWithAnnotations, RetargetOptions.RetargetPrimitiveTypesByTypeCode),
translator.RetargetModifiers(param.RefCustomModifiers, modifiersHaveChanged: out _),
isParamArray: param.IsParamArray,
isParamCollection: param.IsParamCollection,
isParamsArray: param.IsParamsArray,
isParamsCollection: param.IsParamsCollection,
param.RefKind),
translator);

Expand Down Expand Up @@ -1077,8 +1077,8 @@ private PropertySymbol FindPropertyInRetargetedType(PropertySymbol property, Nam
static ParameterSymbol (param, self) => new SignatureOnlyParameterSymbol(
self.Retarget(param.TypeWithAnnotations, RetargetOptions.RetargetPrimitiveTypesByTypeCode),
self.RetargetModifiers(param.RefCustomModifiers, modifiersHaveChanged: out _),
isParamArray: param.IsParamArray,
isParamCollection: param.IsParamCollection,
isParamsArray: param.IsParamsArray,
isParamsCollection: param.IsParamsCollection,
param.RefKind),
this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@ internal sealed class SignatureOnlyParameterSymbol : ParameterSymbol
{
private readonly TypeWithAnnotations _type;
private readonly ImmutableArray<CustomModifier> _refCustomModifiers;
private readonly bool _isParamArray;
private readonly bool _isParamCollection;
private readonly bool _isParamsArray;
private readonly bool _isParamsCollection;
private readonly RefKind _refKind;

public SignatureOnlyParameterSymbol(
TypeWithAnnotations type,
ImmutableArray<CustomModifier> refCustomModifiers,
bool isParamArray,
bool isParamCollection,
bool isParamsArray,
bool isParamsCollection,
RefKind refKind)
{
Debug.Assert((object)type.Type != null);
Debug.Assert(!refCustomModifiers.IsDefault);

_type = type;
_refCustomModifiers = refCustomModifiers;
_isParamArray = isParamArray;
_isParamCollection = isParamCollection;
_isParamsArray = isParamsArray;
_isParamsCollection = isParamsCollection;
_refKind = refKind;
}

public override TypeWithAnnotations TypeWithAnnotations { get { return _type; } }

public override ImmutableArray<CustomModifier> RefCustomModifiers { get { return _refCustomModifiers; } }

public override bool IsParamArray { get { return _isParamArray; } }
public override bool IsParamsArray { get { return _isParamsArray; } }

public override bool IsParamCollection { get { return _isParamCollection; } }
public override bool IsParamsCollection { get { return _isParamsCollection; } }

public override RefKind RefKind { get { return _refKind; } }

Expand Down Expand Up @@ -118,8 +118,8 @@ public override bool Equals(Symbol obj, TypeCompareKind compareKind)
TypeSymbol.Equals(_type.Type, other._type.Type, compareKind) &&
_type.CustomModifiers.Equals(other._type.CustomModifiers) &&
_refCustomModifiers.SequenceEqual(other._refCustomModifiers) &&
_isParamArray == other._isParamArray &&
_isParamCollection == other._isParamCollection &&
_isParamsArray == other._isParamsArray &&
_isParamsCollection == other._isParamsCollection &&
_refKind == other._refKind;
}

Expand All @@ -130,7 +130,7 @@ public override int GetHashCode()
Hash.Combine(
Hash.CombineValues(_type.CustomModifiers),
Hash.Combine(
(_isParamArray || _isParamCollection).GetHashCode(),
(_isParamsArray || _isParamsCollection).GetHashCode(),
((int)_refKind).GetHashCode())));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private static void EnsureRefKindAttributesExist(CSharpCompilation compilation,

internal static void EnsureParamCollectionAttributeExistsAndModifyCompilation(CSharpCompilation compilation, ImmutableArray<ParameterSymbol> parameters, BindingDiagnosticBag diagnostics)
{
if (parameters.LastOrDefault(static (p) => p.IsParamCollection) is { } parameter)
if (parameters.LastOrDefault(static (p) => p.IsParamsCollection) is { } parameter)
{
compilation.EnsureParamCollectionAttributeExistsAndModifyCompilation(diagnostics, GetParameterLocation(parameter));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences
}
}

public override bool IsParamArray
public override bool IsParamsArray
{
get { return !_suppressOptional && _originalParam.IsParamArray; }
get { return !_suppressOptional && _originalParam.IsParamsArray; }
}

public override bool IsParamCollection
public override bool IsParamsCollection
{
get { return !_suppressOptional && _originalParam.IsParamCollection; }
get { return !_suppressOptional && _originalParam.IsParamsCollection; }
}

internal override bool IsMetadataOptional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1499,9 +1499,9 @@ internal sealed override bool IsMetadataOut
internal sealed override MarshalPseudoCustomAttributeData MarshallingInformation
=> GetDecodedWellKnownAttributeData()?.MarshallingInformation;

public sealed override bool IsParamArray => (_parameterSyntaxKind & ParameterSyntaxKind.ParamsParameter) != 0 && this.Type.IsSZArray();
public sealed override bool IsParamsArray => (_parameterSyntaxKind & ParameterSyntaxKind.ParamsParameter) != 0 && this.Type.IsSZArray();

public sealed override bool IsParamCollection => (_parameterSyntaxKind & ParameterSyntaxKind.ParamsParameter) != 0 && !this.Type.IsSZArray();
public sealed override bool IsParamsCollection => (_parameterSyntaxKind & ParameterSyntaxKind.ParamsParameter) != 0 && !this.Type.IsSZArray();

internal override bool IsExtensionMethodThis => (_parameterSyntaxKind & ParameterSyntaxKind.ExtensionThisParameter) != 0;

Expand Down
Loading

0 comments on commit 1c5c7e2

Please sign in to comment.