Repository navigation
Warn dubious negative literal syntax - #24163
Conversation
|
Resuscitates #12459 Addresses the question at https://contributors.scala-lang.org/t/functional-syntax/5062/1 Could use code actions. |
|
The examples are at the far edge of edge cases. Maybe there are bigger warts to justify |
|
Better idea is no option, definitely no error ID. Maybe a bare warning but definitely a rewrite. If it's a syntax quirk that no one ought to ever exploit, it could be an error to write it like that. |
|
I think no option, always warn makes sense. Probably also easier to get the PR merged that way (especially if the option would use a very generic term like |
|
(happy to review after a rebase) |
9826103 to
6f6d667
Compare
| if (op.name == nme.raw.MINUS && isNumericLit) | ||
| simpleExprRest(literal(start), location, canApply = true) | ||
| if isNegatedNumber then | ||
| simpleExprRest(literal(start = in.skipToken()), location, canApply = true) |
There was a problem hiding this comment.
I don't fully understand why we skip a token here. Isn't start the location of the minus sign, per the Scaladoc?
There was a problem hiding this comment.
Yes, literal restores the - op by testing the positions. I'm sorry I changed the name to start, I think that was when I was reading the code. I don't know or remember why the tokens are joined in parser and not in scanner, which joins other things (case class). But it certainly avoids a strval that is "- 42", while incurring the current problem.
Oh, I guess it's useful to call it start for the span to patch.
There was a problem hiding this comment.
Ah OK so it's literal that has odd semantics, this here makes sense then, thanks
| ch match | ||
| case 'x' | 'X' => base = 16; nextChar(); checkNumberChar() | ||
| case 'b' | 'B' => base = 2; nextChar(); checkNumberChar() | ||
| case _ => base = 10; putChar('0') |
There was a problem hiding this comment.
nit: no indentation for a match?
There was a problem hiding this comment.
I was doing that for a while; I guess it still looks natural to me.
Inline fetchLeadingZero in getNumber Use isNegatedNumber to exclude backtick minus `- 42.abs` must remove inner patch to apply `(-42)`.
6f6d667 to
cc07985
Compare
|
If we had hashtags, this would be resolving |
|
We might get hashtags soon :p |
|
I was composing a message... in case I have to read it when reverting. |
|
It seems that breaks Scala parallel collections. It seems quite an impactful change. |
Warns about `- 42` (the misconception that space is significant); and `-42.abs` (the misconception that it parses the same as `-x.abs`, i.e. `-(42.abs)`). Patches are emitted for `-rewrite`. Tweak `prefixExpr` to exclude subsequent expression on the next line. Tweak `simplePattern` to exclude backquoted hyphen as unary minus. Fixes scala#7910 Fixes scala#24162
Warns about
- 42(the misconception that space is significant);and
-42.abs(the misconception that it parses the same as-x.abs, i.e.-(42.abs)).Patches are emitted for
-rewrite.Tweak
prefixExprto exclude subsequent expression on the next line.Tweak
simplePatternto exclude backquoted hyphen as unary minus.Fixes #7910
Fixes #24162