-
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
D-declaration should use declaration expressions #14871
Changes from 1 commit
dc2fe06
d0f94c3
ecce74d
31e9421
7400a9f
d5bede6
7e4ea6e
d39e75e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax | ||
{ | ||
using Microsoft.CodeAnalysis.Syntax.InternalSyntax; | ||
using System.Linq; | ||
|
||
internal partial class LanguageParser : SyntaxParser | ||
{ | ||
|
@@ -7542,7 +7541,7 @@ private StatementSyntax ParseEmbeddedStatement(bool complexCheck) | |
if (expression.Kind == SyntaxKind.SimpleAssignmentExpression) | ||
{ | ||
var assignment = (AssignmentExpressionSyntax)expression; | ||
if (assignment.Left.EnumerateNodes().Any(x => x.RawKind == (int)SyntaxKind.DeclarationExpression)) | ||
if (IsDeconstructionDeclarationLeft(assignment.Left)) | ||
{ | ||
statement = this.AddError(statement, ErrorCode.ERR_BadEmbeddedStmt); | ||
} | ||
|
@@ -8668,6 +8667,28 @@ private static bool TypeFoundInDeconstructionDeclarationVariables(ExpressionSynt | |
} | ||
} | ||
|
||
/// <summary> | ||
/// Returns true if the expression is composed only of nested tuple and declaration expressions. | ||
/// </summary> | ||
private static bool IsDeconstructionDeclarationLeft(ExpressionSyntax node) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is this a dupe of a method from SyntaxExtensions? Consider reusing it instead. #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic is the same, but one is on internal nodes, the other on public nodes. |
||
{ | ||
switch (node.Kind) | ||
{ | ||
case SyntaxKind.TupleExpression: | ||
var arguments = ((TupleExpressionSyntax)node).Arguments; | ||
for (int i = 0; i < arguments.Count; i++) | ||
{ | ||
if (!IsDeconstructionDeclarationLeft(arguments[i].Expression)) return false; | ||
} | ||
|
||
return true; | ||
case SyntaxKind.DeclarationExpression: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
private VariableDesignationSyntax ParseDeconstructionDesignation(bool topLevel = false) | ||
{ | ||
// the two forms of designation are | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,7 +136,6 @@ private void AddVariableExpressions( | |
{ | ||
var t = (TupleExpressionSyntax)component; | ||
foreach (ArgumentSyntax a in t.Arguments) AddVariableExpressions(a.Expression, expressions); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. always use braces. |
||
// TODO REVIEW I think there was a bug there. Are we missing tests? | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed with Neal there was a bug. |
||
} | ||
case SyntaxKind.DeclarationExpression: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2161,14 +2161,6 @@ private static bool IsReplaceableByVar( | |
return true; | ||
} | ||
|
||
//if (simpleName.IsParentKind(SyntaxKind.TypedVariableComponent)) | ||
//{ | ||
// replacementNode = candidateReplacementNode; | ||
// issueSpan = candidateIssueSpan; | ||
// return true; | ||
//} | ||
// TODO REVIEW Are we lacking tests? It seems this code should be needed for DeclarationExpression | ||
|
||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed follow-up issue: #15094 |
||
} | ||
|
||
|
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.
Probably should ensure that the cast is safe (check the kind) and that the Parent is not null. #Closed