From 9d96d4b961e442c60ecbad832f005e6c32e144db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pa=C5=82ka?= Date: Wed, 7 Oct 2020 12:50:59 +0200 Subject: [PATCH] Fix #5441: Java semantics for operations on Long with Float arg --- compiler/src/dotty/tools/backend/jvm/BTypes.scala | 9 ++++++--- tests/run/i5441.check | 3 +++ tests/run/i5441.scala | 8 ++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 tests/run/i5441.check create mode 100644 tests/run/i5441.scala diff --git a/compiler/src/dotty/tools/backend/jvm/BTypes.scala b/compiler/src/dotty/tools/backend/jvm/BTypes.scala index fb399461a03c..8b996d0d5bdb 100644 --- a/compiler/src/dotty/tools/backend/jvm/BTypes.scala +++ b/compiler/src/dotty/tools/backend/jvm/BTypes.scala @@ -290,9 +290,12 @@ abstract class BTypes { } case LONG => - if (other.isIntegralType) LONG - else if (other.isRealType) DOUBLE - else uncomparable + other match { + case INT | BYTE | LONG | CHAR | SHORT => LONG + case DOUBLE => DOUBLE + case FLOAT => FLOAT + case _ => uncomparable + } case FLOAT => if (other == DOUBLE) DOUBLE diff --git a/tests/run/i5441.check b/tests/run/i5441.check new file mode 100644 index 000000000000..d5761e30a2e3 --- /dev/null +++ b/tests/run/i5441.check @@ -0,0 +1,3 @@ +1.164309 +1.164309 +2.3242621 diff --git a/tests/run/i5441.scala b/tests/run/i5441.scala new file mode 100644 index 000000000000..c3183bf2a675 --- /dev/null +++ b/tests/run/i5441.scala @@ -0,0 +1,8 @@ +object Test { + def main(args: Array[String]): Unit = + def a(): Float = java.lang.Float.intBitsToFloat(1079290514) + def b(): Long = 1412906027847L + println(b() % a()) + println((b().toFloat % a().toFloat).toFloat) + println((b().toDouble % a().toDouble).toFloat) +}