Skip to content

Fix adaptation of constants to constant type aliases #18360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 additions & 0 deletions tests/neg/i18340.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@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