Skip to content

Commit

Permalink
Fix adaptation of constants to constant type aliases (#18360)
Browse files Browse the repository at this point in the history
Fixes #18340
  • Loading branch information
dwijnand authored Aug 9, 2023
2 parents d521be5 + fab90ef commit 5eeac92
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4162,7 +4162,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
|| x.tag == LongTag && cls == defn.DoubleClass && x.longValue.toDouble.toLong != x.longValue
then
report.warning(LossyWideningConstantConversion(x.tpe, pt), tree.srcPos)
return adaptConstant(tree, ConstantType(converted))
return readapt(adaptConstant(tree, ConstantType(converted)))
case _ =>

val captured = captureWildcardsCompat(wtp, pt)
Expand Down
36 changes: 36 additions & 0 deletions tests/neg/i18340.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@main def main: Unit =
type T = 3f
val value0: T = -3.5f // error
val value1: T = -100500 // error
val value2: T = -100500L // error
val value3: T = -100500D // error
val value4: T = true // error
val value5: 3f = -100500 // error
val value6: 3f = -100500L // error

type Ti = 3
val value1i: Ti = -100500 // error
val value2i: Ti = -100500L // error
val value0i: Ti = -100500F // error
val value3i: Ti = -100500D // error
val value4i: Ti = true // error
val value5i: 3 = -100500 // error
val value6i: 3 = -100500L // error

type Tl = 3L
val value1l: Tl = -100500 // error
val value2l: Tl = -100500L // error
val value0l: Tl = -100500F // error
val value3l: Tl = -100500D // error
val value4l: Tl = true // error
val value5l: 3L = -100500 // error
val value6l: 3L = -100500L // error

type Td = 3D
val value1d: Td = -100500 // error
val value2d: Td = -100500L // error
val value0d: Td = -100500F // error
val value3d: Td = -100500D // error
val value4d: Td = true // error
val value5d: 3D = -100500 // error
val value6d: 3D = -100500L // error

0 comments on commit 5eeac92

Please sign in to comment.