-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Warn if empty template name 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
Draft
som-snytt
wants to merge
6
commits into
scala:main
Choose a base branch
from
som-snytt:issue/16072-trailing-colon-template-name
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Warn if empty template name has trailing colon #23907
som-snytt
wants to merge
6
commits into
scala:main
from
som-snytt:issue/16072-trailing-colon-template-name
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Note that it's less helpful if scanner issues the indent warning "out of order".
Must follow up givens and enums. |
26646c6
to
53d4ff7
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_: :`.
28e072e
to
d32f88d
Compare
My first swing from Dec 2022 was more direct:
|
When the user accidentally writes `val x_: Int` where the colon belongs to the identifier as an operator suffix, tell them so.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #16072
Fixes #18020
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 it
My 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
def f String = ""
was suggested on the ticket by dwijnand.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
def s_: String = ""
(with a warning).What's the worse that could happen?
TBD