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

Unable to compile constant declaration with self-referencing nameof expression #40

Closed
controlflow opened this issue Jan 19, 2015 · 13 comments · Fixed by #503
Closed

Unable to compile constant declaration with self-referencing nameof expression #40

controlflow opened this issue Jan 19, 2015 · 13 comments · Fixed by #503

Comments

@controlflow
Copy link

const string N = nameof(N);

Currently this code won't compile because of:

error CS0110: The evaluation of the constant value for 'C.N' involves a circular definition

But there is no actual circular reference in evaluation of constant value.
I'm expecting this code to compile fine and constant N to have value "N".

@sharwell
Copy link
Member

This works fine in Visual Studio 2015 Preview (CTP 4). Did something change?

@controlflow
Copy link
Author

@controlflow
Copy link
Author

Yep, it works in CTP4: http://tryroslyn.azurewebsites.net/#b:releases-Dev14CTP4/MYGwhgzhAEDC0G8BQ1XWAewHYQC7TwCcBLLAc2gDloBeaLMAWwFMMAzACkoEoBuJAL5AAA==

var x = nameof(x);

Also works in CTP4, but fails to compile with current 'master'

@paulomorgado
Copy link

I wonder why it no longer works. I don't see the usefulness of this, but it should work.

@theoy theoy added this to the 1.0 milestone Jan 20, 2015
@gafter gafter added the Bug label Jan 20, 2015
@paulomorgado
Copy link

😄

And after saying that, while maintaining an application with SQL concatenations all over the place, I created constants for the table names to have Visual Studio track its usage for me. But even that wasn't that literal.

Well, that beats tostringuing an enum all over the place.

@srivatsn srivatsn modified the milestones: 1.0-rc2, 1.0 (stable) Jan 29, 2015
@theoy theoy changed the title Constant declaration with self-referencing nameof expression Unable to compile constant declaration with self-referencing nameof expression Feb 12, 2015
@gafter
Copy link
Member

gafter commented Feb 14, 2015

@sharwell The spec and implementation of nameof() changed since CTP 4. It used to be a custom syntax and we used to use lookup, but that made the lookup rules complicated and inconsistent because of the custom syntax. The argument is now syntactically an expression and we simply bind it. This error is a consequence of binding the name of the constant in the context of the constant's own initializer.

gafter added a commit to gafter/roslyn that referenced this issue Feb 14, 2015
@gafter gafter added 4 - In Review A fix for the issue is submitted for review. and removed 2 - Ready labels Feb 14, 2015
@Przemyslaw-W
Copy link

but will it be updated to handle such cases? I am also affected by this.

2015-02-14 1:45 GMT+01:00 Neal Gafter notifications@github.com:

@sharwell https://github.com/sharwell The spec and implementation of
nameof() changed since CTP 4. It used to be a custom syntax and we used to
use lookup, but that made the lookup rules complicated and inconsistent
because of the custom syntax. The argument is now syntactically an
expression and we simply bind it. This error is a consequence of binding
the expression in the context of the constant's initializer.


Reply to this email directly or view it on GitHub
#40 (comment).

@gafter
Copy link
Member

gafter commented Feb 16, 2015

@Przemyslaw-W As soon as we integrate pull request #503 this bug will be fixed.

@gafter
Copy link
Member

gafter commented Feb 16, 2015

@Przemyslaw-W fixed now.

@gafter gafter removed the 4 - In Review A fix for the issue is submitted for review. label Feb 16, 2015
@Przemyslaw-W
Copy link

Great, thanks :)

2015-02-16 21:09 GMT+01:00 Neal Gafter notifications@github.com:

@Przemyslaw-W https://github.com/Przemyslaw-W fixed now.


Reply to this email directly or view it on GitHub
#40 (comment).

@gafter gafter assigned AlekseyTs and unassigned gafter Feb 18, 2015
@gafter
Copy link
Member

gafter commented Feb 18, 2015

Assigning to @AlekseyTs for verification.

@AlekseyTs
Copy link
Contributor

Verified

@AlekseyTs AlekseyTs removed their assignment Feb 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants