Skip to content

Commit e2036ec

Browse files
authored
Merge pull request #8456 from dotty-staging/fix-#5309
Fix #5309: Fix subtyping tests on constant types
2 parents 9683136 + 988e5e6 commit e2036ec

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
341341
compareErasedValueType
342342
case ConstantType(v2) =>
343343
tp1 match {
344-
case ConstantType(v1) => v1.value == v2.value
344+
case ConstantType(v1) => v1.value == v2.value && recur(v1.tpe, v2.tpe)
345345
case _ => secondTry
346346
}
347347
case tp2: AnyConstantType =>

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ trait Applications extends Compatibility {
19481948
}
19491949

19501950
/** If `trees` all have numeric value types, and they do not have all the same type,
1951-
* pick a common numeric supertype and convert all constant trees to this type.
1951+
* pick a common numeric supertype and try to convert all constant Int literals to this type.
19521952
* If the resulting trees all have the same type, return them instead of the original ones.
19531953
*/
19541954
def harmonize(trees: List[Tree])(implicit ctx: Context): List[Tree] = {

tests/pos/i5309.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object A {
2+
def foo[T](x: T, y: T): Int = 55
3+
def bar[T](x: T, y: T): List[T] = x :: y :: Nil
4+
val x = foo(23, 23f)
5+
val y = bar(23, 23f)
6+
val z = List(23, 23f)
7+
val x2 = foo(23.0, 23)
8+
val y2 = bar(23.0, 23)
9+
val z2 = List(23.0, 23)
10+
}

0 commit comments

Comments
 (0)