Skip to content

2.13: regression in handling of unary + on numeric literals #465

Closed
@SethTisue

Description

@SethTisue

in very recent 2.13.x nightlies,

scala> (+0): Byte
        ^
       error: type mismatch;
        found   : Int(0)
        required: Byte

as Byte, so also Short and Char. this code has been accepted since Scala 2.8 (the version that introduced weak conformance). Dotty also accepts it.

note that while an initial - is part of the syntax for numeric literals, + is not (SLS 1.3). +0 parses as 0.unary_+. (0.unary_+): Byte gives the same error (and was accepted in previous Scala versions).

@sjrd this was uncovered by Scala.js's test suite, via the community build 🏅

@milessabin I haven't bisected to pinpoint when this regressed, but I bet this has to do with one of your recent changes to ConstantFolder made as part of SIP-23 (PR scala/scala#5310)

SLS 6.24, "Constant Expressions", gives plenty of wiggle room here:

Constant expressions are expressions that the Scala compiler can evaluate to a constant. The definition of "constant expression" depends on the platform

regardless, I think it would be peculiar if +0 weren't covered, given that 0 + 0 is covered ((0 + 0): Byte still compiles)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions