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

Allow mixed declaration and assignment in deconstruction #44476

Merged
Merged
Show file tree
Hide file tree
Changes from 14 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
9 changes: 4 additions & 5 deletions src/Compilers/CSharp/Portable/Binder/Binder_Deconstruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,17 @@ internal BoundExpression BindDeconstruction(AssignmentExpressionSyntax node, Dia
case SyntaxKind.ExpressionStatement:
if (expression != null)
{
// We only allow assignment-only or declaration-only deconstructions at this point.
// Issue https://github.com/dotnet/roslyn/issues/15050 tracks allowing mixed deconstructions.
// For now we give an error when you mix.
Error(diagnostics, ErrorCode.ERR_MixedDeconstructionUnsupported, left);
MessageID.IDS_FeatureMixedDeclarationsAndExpressionsInDeconstruction
.CheckFeatureAvailability(diagnostics, Compilation, node.Location);
}
break;
case SyntaxKind.ForStatement:
if (((ForStatementSyntax)node.Parent).Initializers.Contains(node))
{
if (expression != null)
{
Error(diagnostics, ErrorCode.ERR_MixedDeconstructionUnsupported, left);
MessageID.IDS_FeatureMixedDeclarationsAndExpressionsInDeconstruction
.CheckFeatureAvailability(diagnostics, Compilation, node.Location);
}
}
else
Expand Down
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -5290,9 +5290,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_ThrowMisplaced" xml:space="preserve">
<value>A throw expression is not allowed in this context.</value>
</data>
<data name="ERR_MixedDeconstructionUnsupported" xml:space="preserve">
<value>A deconstruction cannot mix declarations and expressions on the left-hand-side.</value>
</data>
<data name="ERR_DeclarationExpressionNotPermitted" xml:space="preserve">
<value>A declaration is not allowed in this context.</value>
</data>
Expand Down Expand Up @@ -6560,6 +6557,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="IDS_FeatureDiscards" xml:space="preserve">
<value>discards</value>
</data>
<data name="IDS_FeatureMixedDeclarationsAndExpressionsInDeconstruction" xml:space="preserve">
<value>Mixed declarations and expressions in deconstruction</value>
</data>
<data name="IDS_FeatureVarianceSafetyForStaticInterfaceMembers" xml:space="preserve">
<value>variance safety for static interface members</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ internal enum ErrorCode
ERR_NewWithTupleTypeSyntax = 8181,
ERR_PredefinedValueTupleTypeMustBeStruct = 8182,
ERR_DiscardTypeInferenceFailed = 8183,
ERR_MixedDeconstructionUnsupported = 8184,
// ERR_MixedDeconstructionUnsupported = 8184,
ERR_DeclarationExpressionNotPermitted = 8185,
ERR_MustDeclareForeachIteration = 8186,
ERR_TupleElementNamesInDeconstruction = 8187,
Expand Down
4 changes: 4 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/MessageID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ internal enum MessageID
IDS_Parameter = MessageBase + 12789,
IDS_Return = MessageBase + 12790,
IDS_FeatureVarianceSafetyForStaticInterfaceMembers = MessageBase + 12791,
IDS_FeatureMixedDeclarationsAndExpressionsInDeconstruction = MessageBase + 12792,
}

// Message IDs may refer to strings that need to be localized.
Expand Down Expand Up @@ -320,6 +321,9 @@ internal static LanguageVersion RequiredVersion(this MessageID feature)
// Checks are in the LanguageParser unless otherwise noted.
switch (feature)
{
// C# preview features.
case MessageID.IDS_FeatureMixedDeclarationsAndExpressionsInDeconstruction:
return LanguageVersion.Preview;
// C# 9.0 features.
case MessageID.IDS_FeatureLambdaDiscardParameters: // semantic check
case MessageID.IDS_FeatureFunctionPointers:
Expand Down
10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

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

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

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

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

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

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

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

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

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

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

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

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf

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

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf

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

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf

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

10 changes: 5 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf

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

Loading