From 6f993d2b6aad6ae963bcfdb538e0fa3ad9c6a147 Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Fri, 28 Feb 2020 14:03:55 +0100 Subject: [PATCH] fix #8398 - dont parse hex literals as floating point --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 10 ++++++++-- tests/run/i8398.scala | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 tests/run/i8398.scala 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)