-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Warn if name of empty template has trailing colon #23907
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
base: main
Are you sure you want to change the base?
Warn if name of empty template has trailing colon #23907
Conversation
|
Note that it's less helpful if scanner issues the indent warning "out of order". Must follow up givens and enums. |
28e072e to
d32f88d
Compare
|
My first swing from Dec 2022 was more direct: |
|
I wonder how wedded folks are to forms of quote. I like the idea of backticks because of markdown, but the char literal printed by |
d32f88d to
5e4d1c6
Compare
This is to guard the edge case `object X_:` where the user may or may not have intended colon syntax. The next line does not tell us, since it may be indented yet not nested. Therefore, any empty template with a suspicious name will warn. Non-empty templates are given a pass even if written `object X_: :`.
When the user accidentally writes `val x_: Int` where the colon belongs to the identifier as an operator suffix, tell them so.
Why was the information-rich comment too verbose?See below. Why was the ticket worth tackling?If it surprises keynmol, it can surprise any of us. The syntax is a mild language wart but easy enough to compensate for (by linting). (Arguably, people should be persuaded not to give underscore special meaning as a leading or trailing character in a name. For all the reduction in underscore semantics, it is still fundamental to operator names; it is not farfetched to suggest it should be discouraged for other snake purposes, in the absence of backticks, just like embedded dollar.) (Compare making underscore no longer available as an identifier.) How I fixed itMy first attempt was to consider any such name, or such a name followed by indentation. For context, however, it's simpler to query whether the template has a body; I think #16072 (comment) by abgruszecki suggested it to me. The improvement for Why is this PR worth reviewing?There is no syntax change, but only a warning for the two gotchas. The change is confined to the parser. If I spend another hour on it, I'll add dwijnand's idea to split the unintended identifier in What's the worse that could happen?TBD |
|
Indent warning is made awesome --> "awesomaticized". Rebased. Updated check file for change in error id, but dropped the last commit as previous research. |
5e4d1c6 to
524ee92
Compare
524ee92 to
7874d12
Compare
Fixes #16072
Fixes #18020
Warn to guard against colon fusion in
object x_:anddef x_: String.Indent warning is made awesome.