Skip to content

Commit 05055fa

Browse files
Fix BTypes.LONG.maxValueType(BTypes.FLOAT)
The result must be BTypes.FLOAT instead of BTypes.DOUBLE. This implementation incorporates the suggestion at scala#7435 (review).
1 parent 23a6d50 commit 05055fa

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ abstract class BTypes {
297297

298298
case LONG =>
299299
if (other.isIntegralType) LONG
300-
else if (other.isRealType) DOUBLE
300+
else if (other.isRealType) other
301301
else uncomparable
302302

303303
case FLOAT =>

test/junit/scala/tools/nsc/backend/jvm/BTypesTest.scala

+28-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class BTypesTest extends BytecodeTesting {
1919
}
2020
import global.genBCode.bTypes._
2121

22-
def classBTFS(sym: global.Symbol) = global.exitingDelambdafy(classBTypeFromSymbol(sym))
22+
def duringBackend[T](f: => T) = global.exitingDelambdafy(f)
23+
def classBTFS(sym: global.Symbol) = duringBackend { classBTypeFromSymbol(sym) }
2324

2425
def jlo = global.definitions.ObjectClass
2526
def jls = global.definitions.StringClass
@@ -221,4 +222,30 @@ class BTypesTest extends BytecodeTesting {
221222
def maxTypeTest() {
222223

223224
}
225+
226+
@Test
227+
def maxValueTypeATest(): Unit = duringBackend {
228+
assertEquals(LONG, LONG.maxValueType(BYTE))
229+
assertEquals(LONG, LONG.maxValueType(SHORT))
230+
assertEquals(LONG, LONG.maxValueType(CHAR))
231+
assertEquals(LONG, LONG.maxValueType(INT))
232+
assertEquals(LONG, LONG.maxValueType(LONG))
233+
assertEquals(FLOAT, LONG.maxValueType(FLOAT))
234+
assertEquals(DOUBLE, LONG.maxValueType(DOUBLE))
235+
236+
assertUncomparable(LONG, UNIT)
237+
assertUncomparable(LONG, BOOL)
238+
assertUncomparable(LONG, o)
239+
assertUncomparable(LONG, s)
240+
assertUncomparable(LONG, oArr)
241+
assertUncomparable(LONG, method)
242+
243+
def assertUncomparable(t1: PrimitiveBType, t2: BType): Unit = {
244+
try {
245+
t1.maxValueType(t2)
246+
} catch {
247+
case e: AssertionError => assertEquals(s"Cannot compute maxValueType: $t1, $t2", e.getMessage)
248+
}
249+
}
250+
}
224251
}

0 commit comments

Comments
 (0)