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

Suggest that variable with name "page" can't be used in an chstml file #10325

Closed
vsfeedback opened this issue Apr 29, 2024 · 4 comments
Closed
Assignees
Labels
area-compiler Umbrella for all compiler issues author: migration bot 🤖 The issue was created by a issue mover bot. The author may not be the actual author needs more info no recent activity

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


In asp.net core project, cshtml file,
if you have this code:
{
var page = 1;
}
@page

You'll get all kinds of errors, because @page is a reserved word.
As long as you don't try calling @page you're actually fine.


Original Comments

Feedback Bot on 2/8/2024, 05:40 PM:

(private comment, text removed)

@dotnet-policy-service dotnet-policy-service bot added untriaged author: migration bot 🤖 The issue was created by a issue mover bot. The author may not be the actual author labels Apr 29, 2024
@davidwengier
Copy link
Contributor

For the actual issue, that there be a suggestion to not use "page" as a variable, I'm not sure where this goes. I don't think the compiler can do this, as it doesn't understand the C# code. Tooling can't for the same reason. I think this would need an analyzer that looks at the generated code, but so far those all live in the aspnetcore repo: https://github.com/dotnet/aspnetcore/tree/502417e57c9bf7139114de7780d7efc5c0e1b588/src/Components/Analyzers/src

What do you think though @chsienki ? Perhaps this actually a compiler bug that it reports "all kinds of errors", and @page should only ever mean a directive in Razor files? Referring to page in a C# context would still be allowed presumably. Or is that harder than it sounds due to at-escaping in C# being possible?

@chsienki
Copy link
Contributor

chsienki commented May 2, 2024

Yeah, I think to warn we would need an analyzer. Infrastructurally thats not too hard, as we already have the generator, so we could just add an analyzer to MS.CA.Razor.Compiler and it would get picked up.

@jjonescz Can you look at the second part and if there's anything we can do to make the experience better?

@chsienki chsienki added the area-compiler Umbrella for all compiler issues label May 2, 2024
@chsienki chsienki added this to the 17.11 Planning milestone May 2, 2024
@jjonescz
Copy link
Contributor

jjonescz commented May 3, 2024

I cannot reproduce this - I see exactly one error. And it looks good:

error RZ3906: The '@page' directive must precede all other elements defined in a Razor file. 

Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

Please see our Issue Management Policies for more information.

@dotnet-policy-service dotnet-policy-service bot removed this from the 17.11 Planning milestone May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-compiler Umbrella for all compiler issues author: migration bot 🤖 The issue was created by a issue mover bot. The author may not be the actual author needs more info no recent activity
Projects
None yet
Development

No branches or pull requests

4 participants