Skip to content

Commit 5eeac92

Browse files
authored
Fix adaptation of constants to constant type aliases (#18360)
Fixes #18340
2 parents d521be5 + fab90ef commit 5eeac92

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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
10+
11+
type Ti = 3
12+
val value1i: Ti = -100500 // error
13+
val value2i: Ti = -100500L // error
14+
val value0i: Ti = -100500F // error
15+
val value3i: Ti = -100500D // error
16+
val value4i: Ti = true // error
17+
val value5i: 3 = -100500 // error
18+
val value6i: 3 = -100500L // error
19+
20+
type Tl = 3L
21+
val value1l: Tl = -100500 // error
22+
val value2l: Tl = -100500L // error
23+
val value0l: Tl = -100500F // error
24+
val value3l: Tl = -100500D // error
25+
val value4l: Tl = true // error
26+
val value5l: 3L = -100500 // error
27+
val value6l: 3L = -100500L // error
28+
29+
type Td = 3D
30+
val value1d: Td = -100500 // error
31+
val value2d: Td = -100500L // error
32+
val value0d: Td = -100500F // error
33+
val value3d: Td = -100500D // error
34+
val value4d: Td = true // error
35+
val value5d: 3D = -100500 // error
36+
val value6d: 3D = -100500L // error

0 commit comments

Comments
 (0)