Skip to content

Commit 9541fd8

Browse files
author
tomastudja
authored
Bug compatibility with scala/bug#11253 (#1386)
Scalac mistakingly uses Double precision when performing primitive binary operations on Long that take a Float argument. Once this bug is fixed upstream we can conditionally enable the workaround only on affected versions.
1 parent 16d2430 commit 9541fd8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

nscplugin/src/main/scala/scala/scalanative/nscplugin/NirGenExpr.scala

+3
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,9 @@ trait NirGenExpr { self: NirGenPhase =>
985985
}
986986

987987
def binaryOperationType(lty: nir.Type, rty: nir.Type) = (lty, rty) match {
988+
// Bug compatibility with scala/bug/issues/11253
989+
case (Type.Long, Type.Float) =>
990+
Type.Double
988991
case (nir.Type.Ptr, _: nir.Type.RefKind) =>
989992
lty
990993
case (_: nir.Type.RefKind, nir.Type.Ptr) =>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package scala
2+
3+
object LongFloatPrimitiveSuite extends tests.Suite {
4+
@inline def inlineFloat(): Float =
5+
java.lang.Float.intBitsToFloat(1079290514)
6+
@noinline def noinlineFloat(): Float =
7+
java.lang.Float.intBitsToFloat(1079290514)
8+
@inline def inlineLong(): Long =
9+
1412906027847L
10+
@noinline def noinlineLong(): Long =
11+
1412906027847L
12+
13+
test("scala/bug/issues/11253") {
14+
assert(noinlineLong % noinlineFloat == 2.3242621F)
15+
assert(inlineLong % inlineFloat == 2.3242621F)
16+
}
17+
}

0 commit comments

Comments
 (0)