Warn about dollars in names of definitions unless backticked#24690
Warn about dollars in names of definitions unless backticked#24690som-snytt wants to merge 4 commits intoscala:mainfrom
Conversation
They should not be written at all, in fact. ;) |
965c5f3 to
3690e96
Compare
|
This proposal aims to accommodate the two views, which are not entirely incompatible, that strict enforcement is required and yet Java doesn't need it so why does Scala?, where the question is posed with a large dosage of skepticism about warnings. Here, there is no forking compiler option. Definitions with suspect names are disallowed, with a migration warning now and an error later. However, the workaround, to permit the identifier in backquotes, is quite natural and pleasant, as we have all come to savor backquotes in new syntactic contexts. Backquotes are not required for references (usages). CB A |
3fe96a5 to
9754e00
Compare
| case GivenSyntax extends MigrationVersion(future, future) | ||
| case ImplicitParamsWithoutUsing extends MigrationVersion(`3.7`, future) | ||
| case Scala2Implicits extends MigrationVersion(future, future) | ||
| case IdentifierDollars extends MigrationVersion(`3.8`, `3.9`) |
There was a problem hiding this comment.
@Gedochao What's the warning policy for the feature freeze?
Should this be
| case IdentifierDollars extends MigrationVersion(`3.8`, `3.9`) | |
| case IdentifierDollars extends MigrationVersion(`3.10`, `3.11`) |
at this point?
Or can we get away with
| case IdentifierDollars extends MigrationVersion(`3.8`, `3.9`) | |
| case IdentifierDollars extends MigrationVersion(`3.8`, `3.10`) |
even though the warning would then be introduced in a patch version?
There was a problem hiding this comment.
my gut says the former (3.10, 3.11), but I probably could be convinced otherwise.
We haven't had a precedent for this, I guess.
let's discuss it on today's Scala Core.
9754e00 to
8891961
Compare
|
My favorite of the tests |
|
How would that work for |
|
All of those were never supposed to use The only valid use cases are specifically to reproduce an internal name generated by the compiler for obscure binary compatibility reasons. Using backticks is not the "blessed" way of using |
|
Or was I too hasty to complain? The spec says |
|
They won't get any errors, but you still shouldn't define such identifiers. Unless you emulate the compiler's binary encoding and you know what you are doing. |
|
@prolativ That is the intention here.
Backticks are not an absolute escape hatch because (per spec) it's implementation- or platform-dependent what can be permitted. In a separate issue, I'm addressing funky package names. For my benefit, I checked the specese: "host systems may impose some restrictions". (The circumlocution "host system" seems to say the compiler is not required to reject illegal identifiers, but the runtime may crash.) That said, I am not a hard-liner, through also not an arbiter. I considered special-casing lone dollar, since it encodes nothing. I was too lazy, however. |
8891961 to
ee3c07d
Compare
|
Demoted to "never error" because of the bureaucratic overhead. Folks who want an error can ask for it in the usual way, viz., A patch is offered on migration. Maybe it should always emit the patch? since that is a quickfix. As noted above, edge case |
ee3c07d to
ebea5b2
Compare
|
Had a good idea to check in Namer, but the completer loses a bit of context. Edit: the special case is module names, which (it turns out) are a special kind. Avoid warning for case accessors, since it suffices to check the parameter. Don't use Possible todo is to fix |
42f43fa to
1716924
Compare
1716924 to
5e29ee5
Compare
5e29ee5 to
a3e2e97
Compare
Warns on definitions named with embedded dollars, which can be written in backquotes to be accepted quietly.
Fixes #18234
Test from #18563