Skip to content

Fix #5309: Fix subtyping tests on constant types #8456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
compareErasedValueType
case ConstantType(v2) =>
tp1 match {
case ConstantType(v1) => v1.value == v2.value
case ConstantType(v1) => v1.value == v2.value && recur(v1.tpe, v2.tpe)
case _ => secondTry
}
case tp2: AnyConstantType =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,7 @@ trait Applications extends Compatibility {
}

/** If `trees` all have numeric value types, and they do not have all the same type,
* pick a common numeric supertype and convert all constant trees to this type.
* pick a common numeric supertype and try to convert all constant Int literals to this type.
* If the resulting trees all have the same type, return them instead of the original ones.
*/
def harmonize(trees: List[Tree])(implicit ctx: Context): List[Tree] = {
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/i5309.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
object A {
def foo[T](x: T, y: T): Int = 55
def bar[T](x: T, y: T): List[T] = x :: y :: Nil
val x = foo(23, 23f)
val y = bar(23, 23f)
val z = List(23, 23f)
val x2 = foo(23.0, 23)
val y2 = bar(23.0, 23)
val z2 = List(23.0, 23)
}