Skip to content

Commit

Permalink
Report diagnostic for field and value as primary expressions only
Browse files Browse the repository at this point in the history
  • Loading branch information
cston committed Jun 26, 2024
1 parent 5eae7ca commit ce4478c
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ internal RangeVariableSymbol AddRangeVariable(Binder binder, SyntaxToken identif
bool error = false;

Debug.Assert(identifier.Parent is { });
binder.ReportFieldOrValueContextualKeywordConflictIfAny(identifier.Parent, identifier, diagnostics);

foreach (var existingRangeVariable in allRangeVariables.Keys)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/Binder_Deconstruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,6 @@ private BoundExpression BindDeconstructionVariable(
{
SourceLocalSymbol localSymbol = LookupLocal(designation.Identifier);

ReportFieldOrValueContextualKeywordConflictIfAny(designation, designation.Identifier, diagnostics);

// is this a local?
if ((object)localSymbol != null)
{
Expand Down
4 changes: 0 additions & 4 deletions src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3116,8 +3116,6 @@ private BoundExpression BindOutVariableDeclarationArgument(
var designation = (SingleVariableDesignationSyntax)declarationExpression.Designation;
TypeSyntax typeSyntax = declarationExpression.Type;

ReportFieldOrValueContextualKeywordConflictIfAny(designation, designation.Identifier, diagnostics);

// Is this a local?
SourceLocalSymbol localSymbol = this.LookupLocal(designation.Identifier);
if ((object)localSymbol != null)
Expand Down Expand Up @@ -7510,8 +7508,6 @@ private BoundExpression BindMemberAccessWithBoundLeft(

boundLeft = MakeMemberAccessValue(boundLeft, diagnostics);

ReportFieldOrValueContextualKeywordConflictIfAny(right, right.Identifier, diagnostics);

TypeSymbol leftType = boundLeft.Type;

if ((object)leftType != null && leftType.IsDynamic())
Expand Down
3 changes: 0 additions & 3 deletions src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ private UnboundLambda AnalyzeAnonymousFunction(
// x => ...
hasSignature = true;
var simple = (SimpleLambdaExpressionSyntax)syntax;
ReportFieldOrValueContextualKeywordConflictIfAny(simple.Parameter, simple.Parameter.Identifier, diagnostics);
namesBuilder.Add(simple.Parameter.Identifier.ValueText);
break;
case SyntaxKind.ParenthesizedLambdaExpression:
Expand Down Expand Up @@ -193,8 +192,6 @@ private UnboundLambda AnalyzeAnonymousFunction(
}
}

ReportFieldOrValueContextualKeywordConflictIfAny(p, p.Identifier, diagnostics);

namesBuilder.Add(p.Identifier.ValueText);
typesBuilder.Add(type);
refKindsBuilder.Add(refKind);
Expand Down
8 changes: 0 additions & 8 deletions src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,6 @@ private BoundLabeledStatement BindLabeled(LabeledStatementSyntax node, BindingDi
CompoundUseSiteInfo<AssemblySymbol> useSiteInfo = GetNewCompoundUseSiteInfo(diagnostics);
var binder = this.LookupSymbolsWithFallback(result, node.Identifier.ValueText, arity: 0, useSiteInfo: ref useSiteInfo, options: LookupOptions.LabelsOnly);

ReportFieldOrValueContextualKeywordConflictIfAny(node, node.Identifier, diagnostics);

// result.Symbols can be empty in some malformed code, e.g. when a labeled statement is used an embedded statement in an if or foreach statement
// In this case we create new label symbol on the fly, and an error is reported by parser
var symbol = result.Symbols.Count > 0 && result.IsMultiViable ?
Expand Down Expand Up @@ -556,8 +554,6 @@ private BoundStatement BindLocalFunctionStatement(LocalFunctionStatementSyntax n
{
MessageID.IDS_FeatureLocalFunctions.CheckFeatureAvailability(diagnostics, node.Identifier);

ReportFieldOrValueContextualKeywordConflictIfAny(node, node.Identifier, diagnostics);

// already defined symbol in containing block
var localSymbol = this.LookupLocalFunction(node.Identifier);

Expand Down Expand Up @@ -1196,8 +1192,6 @@ internal ImmutableArray<BoundExpression> BindDeclaratorArguments(VariableDeclara

private SourceLocalSymbol LocateDeclaredVariableSymbol(VariableDeclaratorSyntax declarator, TypeSyntax typeSyntax, LocalDeclarationKind outerKind, BindingDiagnosticBag diagnostics)

Check failure on line 1193 in src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs#L1193

src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs(1193,177): error IDE0060: (NETCORE_ENGINEERING_TELEMETRY=Build) Remove unused parameter 'diagnostics' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0060)

Check failure on line 1193 in src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs#L1193

src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs(1193,177): error IDE0060: (NETCORE_ENGINEERING_TELEMETRY=Build) Remove unused parameter 'diagnostics' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0060)

Check failure on line 1193 in src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs#L1193

src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs(1193,177): error IDE0060: (NETCORE_ENGINEERING_TELEMETRY=Build) Remove unused parameter 'diagnostics' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0060)

Check failure on line 1193 in src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs#L1193

src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs(1193,177): error IDE0060: (NETCORE_ENGINEERING_TELEMETRY=Build) Remove unused parameter 'diagnostics' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0060)
{
ReportFieldOrValueContextualKeywordConflictIfAny(declarator, declarator.Identifier, diagnostics);

LocalDeclarationKind kind = outerKind == LocalDeclarationKind.UsingVariable ? LocalDeclarationKind.UsingVariable : LocalDeclarationKind.RegularVariable;
return LocateDeclaredVariableSymbol(declarator.Identifier, typeSyntax, declarator.Initializer, kind);
}
Expand Down Expand Up @@ -3152,8 +3146,6 @@ private BoundCatchBlock BindCatchBlock(CatchClauseSyntax node, ArrayBuilder<Boun
var declaration = node.Declaration;
if (declaration != null)
{
ReportFieldOrValueContextualKeywordConflictIfAny(declaration, declaration.Identifier, diagnostics);

// Note: The type is being bound twice: here and in LocalSymbol.Type. Currently,
// LocalSymbol.Type ignores diagnostics so it seems cleaner to bind the type here
// as well. However, if LocalSymbol.Type is changed to report diagnostics, we'll
Expand Down
5 changes: 0 additions & 5 deletions src/Compilers/CSharp/Portable/Binder/Binder_Symbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,6 @@ private TypeSymbol BindTupleType(TupleTypeSyntax syntax, BindingDiagnosticBag di
hasExplicitNames = true;
CheckTupleMemberName(name, i, nameToken, diagnostics, uniqueFieldNames);
locations.Add(nameToken.GetLocation());
ReportFieldOrValueContextualKeywordConflictIfAny(argumentSyntax, nameToken, diagnostics);
}
else
{
Expand Down Expand Up @@ -872,8 +871,6 @@ protected NamespaceOrTypeOrAliasSymbolWithAnnotations BindNonGenericSimpleNamesp
var result = LookupResult.GetInstance();
LookupOptions options = GetSimpleNameLookupOptions(node, node.Identifier.IsVerbatimIdentifier());

ReportFieldOrValueContextualKeywordConflictIfAny(node, node.Identifier, diagnostics);

CompoundUseSiteInfo<AssemblySymbol> useSiteInfo = GetNewCompoundUseSiteInfo(diagnostics);
this.LookupSymbolsSimpleName(result, qualifierOpt, identifierValueText, 0, basesBeingResolved, options, diagnose: true, useSiteInfo: ref useSiteInfo);
diagnostics.Add(node, useSiteInfo);
Expand Down Expand Up @@ -1213,8 +1210,6 @@ private TypeWithAnnotations BindGenericSimpleNamespaceOrTypeOrAliasSymbol(
diagnostics, basesBeingResolved, qualifierOpt, node, plainName, node.Arity, options);
NamedTypeSymbol resultType;

ReportFieldOrValueContextualKeywordConflictIfAny(node, node.Identifier, diagnostics);

if (isUnboundTypeExpr)
{
if (!IsUnboundTypeAllowed(node))
Expand Down
5 changes: 0 additions & 5 deletions src/Compilers/CSharp/Portable/Binder/ForEachLoopBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,6 @@ private BoundForEachStatement BindForEachPartsWorker(BindingDiagnosticBag diagno
CheckFeatureAvailability(_syntax.AwaitKeyword, MessageID.IDS_FeatureAsyncStreams, diagnostics);
}

if (_syntax is ForEachStatementSyntax forEachStatement)
{
ReportFieldOrValueContextualKeywordConflictIfAny(forEachStatement, forEachStatement.Identifier, diagnostics);
}

// Use the right binder to avoid seeing iteration variable
BoundExpression collectionExpr = originalBinder.GetBinder(_syntax.Expression).BindRValueWithoutTargetType(_syntax.Expression, diagnostics);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,6 @@ private void ComputeParameters()
addRefReadOnlyModifier: false,
diagnostics: diagnostics).Cast<SourceParameterSymbol, ParameterSymbol>();

foreach (var parameter in this.Syntax.ParameterList.Parameters)
{
WithTypeParametersBinder.ReportFieldOrValueContextualKeywordConflictIfAny(parameter, parameter.Identifier, diagnostics);
}

// Note: we don't need to warn on annotations used in #nullable disable context for local functions, as this is handled in binding already

var isVararg = arglistToken.Kind() == SyntaxKind.ArgListKeyword;
Expand Down Expand Up @@ -437,7 +432,6 @@ private ImmutableArray<SourceMethodTypeParameterSymbol> MakeTypeParameters(Bindi
}

SourceMemberContainerTypeSymbol.ReportReservedTypeName(identifier.Text, this.DeclaringCompilation, diagnostics.DiagnosticBag, location);
_binder.ReportFieldOrValueContextualKeywordConflictIfAny(parameter, identifier, diagnostics);

var tpEnclosing = ContainingSymbol.FindEnclosingTypeParameter(name);
if ((object?)tpEnclosing != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4010,9 +4010,6 @@ static void N(int q)
// (24,17): error CS0136: A local or parameter named 'value' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
// int value = 0; // CS0136
Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "value").WithArguments("value").WithLocation(24, 17),
// (24,17): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
// int value = 0; // CS0136
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value = 0").WithArguments("value", "preview").WithLocation(24, 17),
// (25,15): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
// M(value);
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(25, 15),
Expand All @@ -4028,9 +4025,6 @@ static void N(int q)
// (9,17): error CS0136: A local or parameter named 'y' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
// int y = 0; // CS0136
Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "y").WithArguments("y").WithLocation(9, 17),
// (24,17): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
// int value = 0; // CS0136
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value = 0").WithArguments("value", "preview").WithLocation(24, 17),
// (24,17): error CS0136: A local or parameter named 'value' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
// int value = 0; // CS0136
Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "value").WithArguments("value").WithLocation(24, 17),
Expand Down
3 changes: 0 additions & 3 deletions src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2495,9 +2495,6 @@ public byte MyProp
// (12,14): error CS0136: A local or parameter named 'x' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
// long x = 1; // 0136
Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "x").WithArguments("x").WithLocation(12, 14),
// (20,17): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
// int value; // 0136
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(20, 17),
// (20,17): error CS0136: A local or parameter named 'value' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
// int value; // 0136
Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "value").WithArguments("value").WithLocation(20, 17),
Expand Down
Loading

0 comments on commit ce4478c

Please sign in to comment.