From 119752fd6be2179c8ab10641206046b6d3c027a7 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 29 Aug 2019 14:03:52 +0200 Subject: [PATCH 1/3] Don't interpolate downwards to a bottom type If the result of a covariant type variable interpolation would be a bottom type, wait instead. This could make the variable be inferred to its upper bound after all, if we do not need a fully instantiated type right away. --- compiler/src/dotty/tools/dotc/typer/Inferencing.scala | 9 ++++++++- tests/{ => pending}/pos/enum-interop.scala | 0 tests/{ => pending}/pos/i536.scala | 0 tests/run/type-propagation.scala | 7 +++++++ 4 files changed, 15 insertions(+), 1 deletion(-) rename tests/{ => pending}/pos/enum-interop.scala (100%) rename tests/{ => pending}/pos/i536.scala (100%) create mode 100644 tests/run/type-propagation.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index 45c7c74ae459..06c9f1e51443 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -433,7 +433,14 @@ trait Inferencing { this: Typer => else if (!hasUnreportedErrors) if (v.intValue != 0) { typr.println(i"interpolate $tvar in $state in $tree: $tp, fromBelow = ${v.intValue == 1}, $constraint") - tvar.instantiate(fromBelow = v.intValue == 1) + if (true) { + val fromBelow = v.intValue == 1 + val instType = ctx.typeComparer.instanceType(tvar.origin, fromBelow) + if (!(fromBelow && instType.isRef(defn.NothingClass))) + tvar.instantiateWith(instType) + } + else + tvar.instantiate(fromBelow = v.intValue == 1) } else typr.println(i"no interpolation for nonvariant $tvar in $state") } diff --git a/tests/pos/enum-interop.scala b/tests/pending/pos/enum-interop.scala similarity index 100% rename from tests/pos/enum-interop.scala rename to tests/pending/pos/enum-interop.scala diff --git a/tests/pos/i536.scala b/tests/pending/pos/i536.scala similarity index 100% rename from tests/pos/i536.scala rename to tests/pending/pos/i536.scala diff --git a/tests/run/type-propagation.scala b/tests/run/type-propagation.scala new file mode 100644 index 000000000000..b01d716269ac --- /dev/null +++ b/tests/run/type-propagation.scala @@ -0,0 +1,7 @@ +object Test extends App { + def foo: String = { + "abc".asInstanceOf + } + + assert(foo == "abc") +} From 1d48a9308e46e8660d4f9046f3f4b3889d2900cf Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 29 Aug 2019 15:42:47 +0200 Subject: [PATCH 2/3] Reclassify test i536.scala previously compiled since the type argument was inferred to be Nothing. But that inference is useless; it just hides a runtime failure. The issue #536 only complained that the compiler crashed, so having a negative outcome is permissible. --- tests/{pending/pos => neg}/i536.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/{pending/pos => neg}/i536.scala (62%) diff --git a/tests/pending/pos/i536.scala b/tests/neg/i536.scala similarity index 62% rename from tests/pending/pos/i536.scala rename to tests/neg/i536.scala index f2b8f9ce6b28..e96ff48d12f7 100644 --- a/tests/pending/pos/i536.scala +++ b/tests/neg/i536.scala @@ -8,5 +8,5 @@ object Max { val m1 = max(xs) val m2 = max(null) - java.util.Collections.max(null) + java.util.Collections.max(null) // error: Type argument Comparable[_] does not conform to upper bound Comparable[_ >: LazyRef(Comparable[_])] } From fd218352a7511b039daa119da51f2a2732b2684f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 29 Aug 2019 17:22:24 +0200 Subject: [PATCH 3/3] Update fastparse to work around #7130 --- community-build/community-projects/fastparse | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/community-build/community-projects/fastparse b/community-build/community-projects/fastparse index 5bb27834d584..d13f34b47079 160000 --- a/community-build/community-projects/fastparse +++ b/community-build/community-projects/fastparse @@ -1 +1 @@ -Subproject commit 5bb27834d58422282bc12a1b5a03a69dc081338e +Subproject commit d13f34b470790536bf64deed062b7da53b098c05