Skip to content
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

Parse lambda expressions with explicit return type #53827

Merged
merged 6 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6569,15 +6569,16 @@ internal sealed partial class ParenthesizedLambdaExpressionSyntax : LambdaExpres
{
internal readonly GreenNode? attributeLists;
internal readonly GreenNode? modifiers;
internal readonly TypeSyntax? returnType;
internal readonly ParameterListSyntax parameterList;
internal readonly SyntaxToken arrowToken;
internal readonly BlockSyntax? block;
internal readonly ExpressionSyntax? expressionBody;

internal ParenthesizedLambdaExpressionSyntax(SyntaxKind kind, GreenNode? attributeLists, GreenNode? modifiers, ParameterListSyntax parameterList, SyntaxToken arrowToken, BlockSyntax? block, ExpressionSyntax? expressionBody, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations)
internal ParenthesizedLambdaExpressionSyntax(SyntaxKind kind, GreenNode? attributeLists, GreenNode? modifiers, TypeSyntax? returnType, ParameterListSyntax parameterList, SyntaxToken arrowToken, BlockSyntax? block, ExpressionSyntax? expressionBody, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations)
: base(kind, diagnostics, annotations)
{
this.SlotCount = 6;
this.SlotCount = 7;
if (attributeLists != null)
{
this.AdjustFlagsAndWidth(attributeLists);
Expand All @@ -6588,6 +6589,11 @@ internal ParenthesizedLambdaExpressionSyntax(SyntaxKind kind, GreenNode? attribu
this.AdjustFlagsAndWidth(modifiers);
this.modifiers = modifiers;
}
if (returnType != null)
{
this.AdjustFlagsAndWidth(returnType);
this.returnType = returnType;
}
this.AdjustFlagsAndWidth(parameterList);
this.parameterList = parameterList;
this.AdjustFlagsAndWidth(arrowToken);
Expand All @@ -6604,11 +6610,11 @@ internal ParenthesizedLambdaExpressionSyntax(SyntaxKind kind, GreenNode? attribu
}
}

internal ParenthesizedLambdaExpressionSyntax(SyntaxKind kind, GreenNode? attributeLists, GreenNode? modifiers, ParameterListSyntax parameterList, SyntaxToken arrowToken, BlockSyntax? block, ExpressionSyntax? expressionBody, SyntaxFactoryContext context)
internal ParenthesizedLambdaExpressionSyntax(SyntaxKind kind, GreenNode? attributeLists, GreenNode? modifiers, TypeSyntax? returnType, ParameterListSyntax parameterList, SyntaxToken arrowToken, BlockSyntax? block, ExpressionSyntax? expressionBody, SyntaxFactoryContext context)
: base(kind)
{
this.SetFactoryContext(context);
this.SlotCount = 6;
this.SlotCount = 7;
if (attributeLists != null)
{
this.AdjustFlagsAndWidth(attributeLists);
Expand All @@ -6619,6 +6625,11 @@ internal ParenthesizedLambdaExpressionSyntax(SyntaxKind kind, GreenNode? attribu
this.AdjustFlagsAndWidth(modifiers);
this.modifiers = modifiers;
}
if (returnType != null)
{
this.AdjustFlagsAndWidth(returnType);
this.returnType = returnType;
}
this.AdjustFlagsAndWidth(parameterList);
this.parameterList = parameterList;
this.AdjustFlagsAndWidth(arrowToken);
Expand All @@ -6635,10 +6646,10 @@ internal ParenthesizedLambdaExpressionSyntax(SyntaxKind kind, GreenNode? attribu
}
}

internal ParenthesizedLambdaExpressionSyntax(SyntaxKind kind, GreenNode? attributeLists, GreenNode? modifiers, ParameterListSyntax parameterList, SyntaxToken arrowToken, BlockSyntax? block, ExpressionSyntax? expressionBody)
internal ParenthesizedLambdaExpressionSyntax(SyntaxKind kind, GreenNode? attributeLists, GreenNode? modifiers, TypeSyntax? returnType, ParameterListSyntax parameterList, SyntaxToken arrowToken, BlockSyntax? block, ExpressionSyntax? expressionBody)
: base(kind)
{
this.SlotCount = 6;
this.SlotCount = 7;
if (attributeLists != null)
{
this.AdjustFlagsAndWidth(attributeLists);
Expand All @@ -6649,6 +6660,11 @@ internal ParenthesizedLambdaExpressionSyntax(SyntaxKind kind, GreenNode? attribu
this.AdjustFlagsAndWidth(modifiers);
this.modifiers = modifiers;
}
if (returnType != null)
{
this.AdjustFlagsAndWidth(returnType);
this.returnType = returnType;
}
this.AdjustFlagsAndWidth(parameterList);
this.parameterList = parameterList;
this.AdjustFlagsAndWidth(arrowToken);
Expand All @@ -6667,6 +6683,7 @@ internal ParenthesizedLambdaExpressionSyntax(SyntaxKind kind, GreenNode? attribu

public override Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<AttributeListSyntax> AttributeLists => new Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<AttributeListSyntax>(this.attributeLists);
public override Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken> Modifiers => new Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken>(this.modifiers);
public TypeSyntax? ReturnType => this.returnType;
/// <summary>ParameterListSyntax node representing the list of parameters for the lambda expression.</summary>
public ParameterListSyntax ParameterList => this.parameterList;
/// <summary>SyntaxToken representing equals greater than.</summary>
Expand All @@ -6687,10 +6704,11 @@ internal ParenthesizedLambdaExpressionSyntax(SyntaxKind kind, GreenNode? attribu
{
0 => this.attributeLists,
1 => this.modifiers,
2 => this.parameterList,
3 => this.arrowToken,
4 => this.block,
5 => this.expressionBody,
2 => this.returnType,
3 => this.parameterList,
4 => this.arrowToken,
5 => this.block,
6 => this.expressionBody,
_ => null,
};

Expand All @@ -6699,11 +6717,11 @@ internal ParenthesizedLambdaExpressionSyntax(SyntaxKind kind, GreenNode? attribu
public override void Accept(CSharpSyntaxVisitor visitor) => visitor.VisitParenthesizedLambdaExpression(this);
public override TResult Accept<TResult>(CSharpSyntaxVisitor<TResult> visitor) => visitor.VisitParenthesizedLambdaExpression(this);

public ParenthesizedLambdaExpressionSyntax Update(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<AttributeListSyntax> attributeLists, Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken> modifiers, ParameterListSyntax parameterList, SyntaxToken arrowToken, BlockSyntax block, ExpressionSyntax expressionBody)
public ParenthesizedLambdaExpressionSyntax Update(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<AttributeListSyntax> attributeLists, Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken> modifiers, TypeSyntax returnType, ParameterListSyntax parameterList, SyntaxToken arrowToken, BlockSyntax block, ExpressionSyntax expressionBody)
{
if (attributeLists != this.AttributeLists || modifiers != this.Modifiers || parameterList != this.ParameterList || arrowToken != this.ArrowToken || block != this.Block || expressionBody != this.ExpressionBody)
if (attributeLists != this.AttributeLists || modifiers != this.Modifiers || returnType != this.ReturnType || parameterList != this.ParameterList || arrowToken != this.ArrowToken || block != this.Block || expressionBody != this.ExpressionBody)
{
var newNode = SyntaxFactory.ParenthesizedLambdaExpression(attributeLists, modifiers, parameterList, arrowToken, block, expressionBody);
var newNode = SyntaxFactory.ParenthesizedLambdaExpression(attributeLists, modifiers, returnType, parameterList, arrowToken, block, expressionBody);
var diags = GetDiagnostics();
if (diags?.Length > 0)
newNode = newNode.WithDiagnosticsGreen(diags);
Expand All @@ -6717,15 +6735,15 @@ public ParenthesizedLambdaExpressionSyntax Update(Microsoft.CodeAnalysis.Syntax.
}

internal override GreenNode SetDiagnostics(DiagnosticInfo[]? diagnostics)
=> new ParenthesizedLambdaExpressionSyntax(this.Kind, this.attributeLists, this.modifiers, this.parameterList, this.arrowToken, this.block, this.expressionBody, diagnostics, GetAnnotations());
=> new ParenthesizedLambdaExpressionSyntax(this.Kind, this.attributeLists, this.modifiers, this.returnType, this.parameterList, this.arrowToken, this.block, this.expressionBody, diagnostics, GetAnnotations());

internal override GreenNode SetAnnotations(SyntaxAnnotation[]? annotations)
=> new ParenthesizedLambdaExpressionSyntax(this.Kind, this.attributeLists, this.modifiers, this.parameterList, this.arrowToken, this.block, this.expressionBody, GetDiagnostics(), annotations);
=> new ParenthesizedLambdaExpressionSyntax(this.Kind, this.attributeLists, this.modifiers, this.returnType, this.parameterList, this.arrowToken, this.block, this.expressionBody, GetDiagnostics(), annotations);

internal ParenthesizedLambdaExpressionSyntax(ObjectReader reader)
: base(reader)
{
this.SlotCount = 6;
this.SlotCount = 7;
var attributeLists = (GreenNode?)reader.ReadValue();
if (attributeLists != null)
{
Expand All @@ -6738,6 +6756,12 @@ internal ParenthesizedLambdaExpressionSyntax(ObjectReader reader)
AdjustFlagsAndWidth(modifiers);
this.modifiers = modifiers;
}
var returnType = (TypeSyntax?)reader.ReadValue();
if (returnType != null)
{
AdjustFlagsAndWidth(returnType);
this.returnType = returnType;
}
var parameterList = (ParameterListSyntax)reader.ReadValue();
AdjustFlagsAndWidth(parameterList);
this.parameterList = parameterList;
Expand All @@ -6763,6 +6787,7 @@ internal override void WriteTo(ObjectWriter writer)
base.WriteTo(writer);
writer.WriteValue(this.attributeLists);
writer.WriteValue(this.modifiers);
writer.WriteValue(this.returnType);
writer.WriteValue(this.parameterList);
writer.WriteValue(this.arrowToken);
writer.WriteValue(this.block);
Expand Down Expand Up @@ -33691,7 +33716,7 @@ public override CSharpSyntaxNode VisitRefExpression(RefExpressionSyntax node)
=> node.Update((SyntaxToken)Visit(node.RefKeyword), (ExpressionSyntax)Visit(node.Expression));

public override CSharpSyntaxNode VisitParenthesizedLambdaExpression(ParenthesizedLambdaExpressionSyntax node)
=> node.Update(VisitList(node.AttributeLists), VisitList(node.Modifiers), (ParameterListSyntax)Visit(node.ParameterList), (SyntaxToken)Visit(node.ArrowToken), (BlockSyntax)Visit(node.Block), (ExpressionSyntax)Visit(node.ExpressionBody));
=> node.Update(VisitList(node.AttributeLists), VisitList(node.Modifiers), (TypeSyntax)Visit(node.ReturnType), (ParameterListSyntax)Visit(node.ParameterList), (SyntaxToken)Visit(node.ArrowToken), (BlockSyntax)Visit(node.Block), (ExpressionSyntax)Visit(node.ExpressionBody));

public override CSharpSyntaxNode VisitInitializerExpression(InitializerExpressionSyntax node)
=> node.Update((SyntaxToken)Visit(node.OpenBraceToken), VisitList(node.Expressions), (SyntaxToken)Visit(node.CloseBraceToken));
Expand Down Expand Up @@ -35499,15 +35524,15 @@ public RefExpressionSyntax RefExpression(SyntaxToken refKeyword, ExpressionSynta
return result;
}

public ParenthesizedLambdaExpressionSyntax ParenthesizedLambdaExpression(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<AttributeListSyntax> attributeLists, Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken> modifiers, ParameterListSyntax parameterList, SyntaxToken arrowToken, BlockSyntax? block, ExpressionSyntax? expressionBody)
public ParenthesizedLambdaExpressionSyntax ParenthesizedLambdaExpression(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<AttributeListSyntax> attributeLists, Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken> modifiers, TypeSyntax? returnType, ParameterListSyntax parameterList, SyntaxToken arrowToken, BlockSyntax? block, ExpressionSyntax? expressionBody)
{
#if DEBUG
if (parameterList == null) throw new ArgumentNullException(nameof(parameterList));
if (arrowToken == null) throw new ArgumentNullException(nameof(arrowToken));
if (arrowToken.Kind != SyntaxKind.EqualsGreaterThanToken) throw new ArgumentException(nameof(arrowToken));
#endif

return new ParenthesizedLambdaExpressionSyntax(SyntaxKind.ParenthesizedLambdaExpression, attributeLists.Node, modifiers.Node, parameterList, arrowToken, block, expressionBody, this.context);
return new ParenthesizedLambdaExpressionSyntax(SyntaxKind.ParenthesizedLambdaExpression, attributeLists.Node, modifiers.Node, returnType, parameterList, arrowToken, block, expressionBody, this.context);
}

public InitializerExpressionSyntax InitializerExpression(SyntaxKind kind, SyntaxToken openBraceToken, Microsoft.CodeAnalysis.Syntax.InternalSyntax.SeparatedSyntaxList<ExpressionSyntax> expressions, SyntaxToken closeBraceToken)
Expand Down Expand Up @@ -40393,15 +40418,15 @@ public static RefExpressionSyntax RefExpression(SyntaxToken refKeyword, Expressi
return result;
}

public static ParenthesizedLambdaExpressionSyntax ParenthesizedLambdaExpression(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<AttributeListSyntax> attributeLists, Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken> modifiers, ParameterListSyntax parameterList, SyntaxToken arrowToken, BlockSyntax? block, ExpressionSyntax? expressionBody)
public static ParenthesizedLambdaExpressionSyntax ParenthesizedLambdaExpression(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<AttributeListSyntax> attributeLists, Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken> modifiers, TypeSyntax? returnType, ParameterListSyntax parameterList, SyntaxToken arrowToken, BlockSyntax? block, ExpressionSyntax? expressionBody)
{
#if DEBUG
if (parameterList == null) throw new ArgumentNullException(nameof(parameterList));
if (arrowToken == null) throw new ArgumentNullException(nameof(arrowToken));
if (arrowToken.Kind != SyntaxKind.EqualsGreaterThanToken) throw new ArgumentException(nameof(arrowToken));
#endif

return new ParenthesizedLambdaExpressionSyntax(SyntaxKind.ParenthesizedLambdaExpression, attributeLists.Node, modifiers.Node, parameterList, arrowToken, block, expressionBody);
return new ParenthesizedLambdaExpressionSyntax(SyntaxKind.ParenthesizedLambdaExpression, attributeLists.Node, modifiers.Node, returnType, parameterList, arrowToken, block, expressionBody);
}

public static InitializerExpressionSyntax InitializerExpression(SyntaxKind kind, SyntaxToken openBraceToken, Microsoft.CodeAnalysis.Syntax.InternalSyntax.SeparatedSyntaxList<ExpressionSyntax> expressions, SyntaxToken closeBraceToken)
Expand Down
Loading