Skip to content

Commit edcc705

Browse files
committed
Fix adaptation of constants to constant type aliases
Fixes #18340
1 parent 3c95134 commit edcc705

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4162,7 +4162,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
41624162
|| x.tag == LongTag && cls == defn.DoubleClass && x.longValue.toDouble.toLong != x.longValue
41634163
then
41644164
report.warning(LossyWideningConstantConversion(x.tpe, pt), tree.srcPos)
4165-
return adaptConstant(tree, ConstantType(converted))
4165+
return readapt(adaptConstant(tree, ConstantType(converted)))
41664166
case _ =>
41674167

41684168
val captured = captureWildcardsCompat(wtp, pt)

tests/neg/i18340.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@main def main: Unit =
2+
type T = 3f
3+
val value0: T = -3.5f // error
4+
val value1: T = -100500 // error
5+
val value2: T = -100500L // error
6+
val value3: T = -100500D // error
7+
val value4: T = true // error
8+
val value5: 3f = -100500 // error
9+
val value6: 3f = -100500L // error

0 commit comments

Comments
 (0)