aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorodersky <odersky@gmail.com>2015-10-25 13:39:10 +0100
committerodersky <odersky@gmail.com>2015-10-25 13:39:10 +0100
commitecf62cf18b43b5a39e973bdc8087675a24337ce0 (patch)
tree33619b5d8f9cf84797b547d7e2bf50c4fcb95dc7 /src
parent77f7b2a4e988aa610a3cf7d92bb8838359127176 (diff)
parent0a386a85da9c6df97bf2cb6627e1f905af17c123 (diff)
downloaddotty-ecf62cf18b43b5a39e973bdc8087675a24337ce0.tar.gz
dotty-ecf62cf18b43b5a39e973bdc8087675a24337ce0.tar.bz2
dotty-ecf62cf18b43b5a39e973bdc8087675a24337ce0.zip
Merge pull request #843 from dotty-staging/fix-#830
Fix #830: Compiler hangs on implicit search with singleton &/|
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index f2a4c9e1e..1afaed60d 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -123,7 +123,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
pendingSubTypes = new mutable.HashSet[(Type, Type)]
ctx.log(s"!!! deep subtype recursion involving ${tp1.show} <:< ${tp2.show}, constraint = ${state.constraint.show}")
ctx.log(s"!!! constraint = ${constraint.show}")
- assert(!ctx.settings.YnoDeepSubtypes.value)
+ if (ctx.settings.YnoDeepSubtypes.value) throw new Error("deep subtype")
if (Config.traceDeepSubTypeRecursions && !this.isInstanceOf[ExplainingTypeComparer])
ctx.log(TypeComparer.explained(implicit ctx => ctx.typeComparer.isSubType(tp1, tp2)))
}
@@ -779,8 +779,24 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
else {
val t2 = mergeIfSub(tp2, tp1)
if (t2.exists) t2
- else andType(tp1, tp2)
- }
+ else tp1 match {
+ case tp1: ConstantType =>
+ tp2 match {
+ case tp2: ConstantType =>
+ // Make use of the fact that the intersection of two constant types
+ // types which are not subtypes of each other is known to be empty.
+ // Note: The same does not apply to singleton types in general.
+ // E.g. we could have a pattern match against `x.type & y.type`
+ // which might succeed if `x` and `y` happen to be the same ref
+ // at run time. It would not work to replace that with `Nothing`.
+ // However, maybe we can still apply the replacement to
+ // types which are not explicitly written.
+ defn.NothingType
+ case _ => andType(tp1, tp2)
+ }
+ case _ => andType(tp1, tp2)
+ }
+ }
}
}
}