Skip to content

False negative dubious negative Long literal syntaxΒ #26564

Closed

Description

@xuwei-k

Compiler version

  • 3.9.0-RC3
  • 3.10.0-RC1-bin-20260716-61591f7-NIGHTLY

Minimized example

//> using scala 3.9.0-RC3

def f = -2L.abs

Output

no warnings

Expectation

expect warning same as negative Int literal

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`

Activity

  1. Tomgit473 commented on Jul 16, 2026

    @Tomgit473
    Contributor

    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.

  2. added and removed
    stat:needs triageEvery issue needs to have an "area" and "itype" label
    on Jul 24, 2026
  3. Ichoran commented on Jul 26, 2026

    @Ichoran

    Note that this is not limited to Long. Extension methods on Int show the same behavior.

  4. SolalPirelli commented on Jul 27, 2026

    @SolalPirelli
    Contributor

    @Tomgit473 always good to see new faces who want to solve things, have you made any progress on this / do you need any help?

  5. Tomgit473 commented on Jul 27, 2026

    @Tomgit473
    Contributor

    @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!

  6. added a commit that references this issue on Aug 10, 2026
    0aac894
  7. added this to the 3.10.0 milestone on Aug 26, 2026
  8. added 2 commits that reference this issue on Nov 8, 2026
    f775d76
    9ba29ef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions