diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index c245a8bf98d0..fb421fb2b675 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -558,9 +558,15 @@ class Typer extends Namer case _ => } else if (target.isRef(defn.FloatClass)) - return lit(floatFromDigits(digits)) + tree.kind match { + case Whole(16) => // cant parse hex literal as float + case _ => return lit(floatFromDigits(digits)) + } else if (target.isRef(defn.DoubleClass)) - return lit(doubleFromDigits(digits)) + tree.kind match { + case Whole(16) => // cant parse hex literal as double + case _ => return lit(doubleFromDigits(digits)) + } else if (target.isValueType && isFullyDefined(target, ForceDegree.none)) { // If expected type is defined with a FromDigits instance, use that one val fromDigitsCls = tree.kind match { diff --git a/tests/run/i8398.scala b/tests/run/i8398.scala new file mode 100644 index 000000000000..5d5364203423 --- /dev/null +++ b/tests/run/i8398.scala @@ -0,0 +1,3 @@ +@main def Test = + assert((0x7FFF_FFFF : Float) == 2.14748365E9f) + assert((0x7FFF_FFFF : Double) == 2.147483647E9)