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

Do not parse methods with accessibility modifiers as local functions (alt) #74495

Merged
merged 55 commits into from
Jul 26, 2024

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Jul 23, 2024

Fixes #74482

Alternate to #74484

Also, makes the parser much better about errant close curly tokens causing type-members to now show up within a namespace, instead of in the preceding type-declaration.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 23, 2024
@CyrusNajmabadi CyrusNajmabadi requested a review from 333fred July 23, 2024 15:24
@CyrusNajmabadi
Copy link
Member Author

Currently draft. But pulling @333fred in to get thoughts.

{
internal abstract partial class TypeDeclarationSyntax
{
public abstract TypeDeclarationSyntax UpdateCore(
Copy link
Member Author

Choose a reason for hiding this comment

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

Added as the internal syntax generator doesn't include these abstract/overrides in that model.

Copy link
Member Author

Choose a reason for hiding this comment

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

i really don't ove this. but this mirrors how normal public syntax works. And, importantly, means that if we ever add a new type-decl subclass, we'll know we have to ensuer that thsi works.

@RikkiGibson
Copy link
Contributor

It looks like some editor features tests are failing

@CyrusNajmabadi
Copy link
Member Author

It looks like some editor features tests are failing

Both cases where hte new behavior in the presence of these error cases is fine :)

@CyrusNajmabadi
Copy link
Member Author

@RikkiGibson this is ready for review.

src/Compilers/CSharp/Portable/Parser/LanguageParser.cs Outdated Show resolved Hide resolved
}
""";
UsingTree(text,
// (5,5): error CS1519: Invalid token '}' in class, record, struct, or interface member declaration
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a little uneasy about this diagnostic. There is nothing wrong in itself with putting a } here. The problem is that the } is followed by a non-type/non-namespace member declaration.

I would be more comfortable with a diagnostic which blames the member private void M() while implying that we didn't expect the preceding }.
Something like: A namespace cannot directly contain members such as fields, methods or statements. Did you mean to include it as a member of type 'Type'? (similar message to ERR_NamespaceUnexpected)

It's possible that I just need to sit with it a bit and I'll come around. I'm not sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

this is fair. i'll think on it too and check in with you later.

Copy link
Member Author

Choose a reason for hiding this comment

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

having thought about it, i'm ok with this error message. it is invalid. Now it happens to be invalid because of what we see later, btu i'm ok with that.

note: i'm not pushing back strongly. if you do want a specific error here, lmk.

Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi Jul 26, 2024

Choose a reason for hiding this comment

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

A namespace cannot directly contain members such as fields, methods or statements.

i'm not a fan of this primarily because the tree we produce won't jive with this. The node will appear inside the class from all other perspectives. But i do think we can clarify the error we put on the }. Something like Errant '}' found between type members. By saying 'between' we call out that there is another member tha tfollows.

@CyrusNajmabadi CyrusNajmabadi merged commit 2f5f117 into dotnet:main Jul 26, 2024
28 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the localFunctionVsMethod2 branch July 26, 2024 17:12
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 26, 2024
@RikkiGibson RikkiGibson modified the milestones: Next, 17.12 P1 Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Visual Studio insists on autocorrecting the method name I type to a similarly named field
3 participants