You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
False negative dubious negative Long literal syntaxΒ #26564
Welcome to Scala 3.9.0-RC3 (21.0.11, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> def f = -2.abs
1 warning found
-- [E028] Syntax Warning: ------------------------------------------------------
1 |def f = -2.abs
| ^
| Illegal literal
|
| longer explanation available when compiling with `-explain`
I'd like to work on this. The issue is in literalOf (in Parsers.scala) INTLIT/DECILIT/EXPOLIT get wrapped in a Number tree, but LONGLIT, FLOATLIT, and DOUBLELIT are built as plain Literal trees instead, since they have a suffix-fixed type. The warning check in simpleExprRest only matches on case Number(n, _) if n(0) == '-', so it silently skips these three literal kinds. I'll extend that check to also catch negated Literals of type Long/Float/Double.
@SolalPirelli Thanks! I've dug into the parser and found the root cause simpleExprRest only checks for a Number tree, but Long/Float/Double-suffixed literals get built as plain Literal trees instead, so they skip the check entirely. I have a fix sketched out for that. Now looking into lchoran's point about extension methods on Int too trying to confirm whether that's a separate issue (infix call syntax bypassing the check entirely) before I fold it into the same fix. Will have a PR up soon, will ping if I get stuck!
Activity
Tomgit473 commentedon Jul 16, 2026
I'd like to work on this. The issue is in literalOf (in Parsers.scala) INTLIT/DECILIT/EXPOLIT get wrapped in a Number tree, but LONGLIT, FLOATLIT, and DOUBLELIT are built as plain Literal trees instead, since they have a suffix-fixed type. The warning check in simpleExprRest only matches on case Number(n, _) if n(0) == '-', so it silently skips these three literal kinds. I'll extend that check to also catch negated Literals of type Long/Float/Double.
Ichoran commentedon Jul 26, 2026
Note that this is not limited to
Long. Extension methods onIntshow the same behavior.SolalPirelli commentedon Jul 27, 2026
@Tomgit473 always good to see new faces who want to solve things, have you made any progress on this / do you need any help?
Tomgit473 commentedon Jul 27, 2026
@SolalPirelli Thanks! I've dug into the parser and found the root cause
simpleExprRestonly checks for aNumbertree, butLong/Float/Double-suffixed literals get built as plainLiteraltrees instead, so they skip the check entirely. I have a fix sketched out for that. Now looking into lchoran's point about extension methods onInttoo trying to confirm whether that's a separate issue (infix call syntax bypassing the check entirely) before I fold it into the same fix. Will have a PR up soon, will ping if I get stuck!Fix #26564: warn on dubious negative Long/Float/Double literal syntax (β¦
Merge pull request #1359 from scala/backport-lts-3.9-26725
Merge pull request #1343 from scala/backport-lts-3.3-26725