Skip to content

Conversation

@AlekseyTs
Copy link
Contributor

Related to #41704.

@AlekseyTs
Copy link
Contributor Author

@cston, @RikkiGibson, @dotnet/roslyn-compiler Please review.

// extern alias A;
Diagnostic(ErrorCode.ERR_BadExternAlias, "A").WithArguments("A").WithLocation(2, 14)
);
}
Copy link
Contributor

@cston cston Mar 2, 2020

Choose a reason for hiding this comment

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

} [](start = 8, length = 1)

Is there a test of a type (or namespace) followed by a local function? #Resolved

Copy link
Contributor Author

@AlekseyTs AlekseyTs Mar 2, 2020

Choose a reason for hiding this comment

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

Is there a test of a type (or namespace) followed by a local function?

No, those are no different than any other top-level statements - all of them are wrapped into GlobalStatementSyntax


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

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be useful to have such a test so it's clear that is that top-level methods are treated as top-level statements.

It would also make clear the error message is "Top-level statements must precede namespace and type declarations" which might be a little confusing when a member method is treated as a top-level statement because of a misplaced } before the method.


In reply to: 386553202 [](ancestors = 386553202,386529251)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would also make clear the error message is "Top-level statements must precede namespace and type declarations" which might be a little confusing when a member method is treated as a top-level statement because of a misplaced } before the method.

Is there any specific suggestion in this statement? Could you please elaborate?


In reply to: 386558178 [](ancestors = 386558178,386553202,386529251)

Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably a common mistake to copy and paste methods unintentionally as top-level methods so perhaps the diagnostic message should mention methods explicitly. For instance: "Top-level statements and functions must precede namespace and type declarations."


In reply to: 386563032 [](ancestors = 386563032,386558178,386553202,386529251)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For instance: "Top-level statements and functions must precede namespace and type declarations."

"Top-level functions" is a different feature. Local function are not them. I think, the message is clear enough, it points out that the statement is a top-level statement, so if that is not expected it is pretty clear what to look for (unexpected end of type declaration, etc.). I'll add a PROTOTYPE comment to follow-up if that would be necessary.


In reply to: 386566431 [](ancestors = 386566431,386563032,386558178,386553202,386529251)

@AlekseyTs
Copy link
Contributor Author

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

@AlekseyTs
Copy link
Contributor Author

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

1 similar comment
@AlekseyTs
Copy link
Contributor Author

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

@AlekseyTs AlekseyTs merged commit c6dbaec into dotnet:features/SimplePrograms Mar 3, 2020
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.

3 participants