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

Disallow declaration of variables within constructor/field initializers. #13510

Merged
merged 1 commit into from
Sep 1, 2016

Conversation

AlekseyTs
Copy link
Contributor

Related to #12597.

@dotnet/roslyn-compiler, @gafter Please review.

@@ -5012,11 +5193,22 @@ public C(object b)
}
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe);
#if ALLOW_IN_CONSTRUCTOR_INITIALIZER
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand the purpose of the ALLOW_IN_CONSTRUCTOR_INITIALIZER pragma. Why not just update the test code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose is to keep expectations, we are planning to allow declarations in these contexts in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Thanks

@jcouv
Copy link
Member

jcouv commented Aug 31, 2016

LGTM but I would not introduce #if blocks.

@AlekseyTs
Copy link
Contributor Author

Ping. @dotnet/roslyn-compiler, @gafter Please review.

@@ -4947,4 +4947,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_OutVarDeconstructionIsNotSupported" xml:space="preserve">
<value>Deconstruction is not supported for an 'out' argument.</value>
</data>
<data name="ERR_ExpressionVariableInConstructorOrFieldInitializer" xml:space="preserve">
<value>Out variable or pattern variable declarations are not allowed within constructor/field/auto-implemented property initializers.</value>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider separating cases with comma for consistency with other errors. And remove auto-implemented if not necessary. Perhaps: ... not allowed within constructors, field initializers, or property initializers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I believe the first "or" should be "and" (they are both forbidden), so I suggest

Out variable and pattern variable declarations are not allowed within constructor initializers, field initializers, or property initializers.

This is long-winded enough that you could consider specializing it.


In reply to: 77212251 [](ancestors = 77212251)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #13528.

@gafter
Copy link
Member

gafter commented Sep 1, 2016

Other than a slight wording change on the diagnostic, LGTM

@AlekseyTs AlekseyTs merged commit 60362d8 into dotnet:master Sep 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants