From f6d1153e193045ad4d8a1564e3c0cdb49b853a5b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 6 Dec 2015 12:44:00 +0100 Subject: Avoid false positives when extracting AppliedType --- src/dotty/tools/dotc/core/TypeApplications.scala | 8 +++++++- src/dotty/tools/dotc/core/Types.scala | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src/dotty') diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index db7550402..ab15b3e1a 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -133,7 +133,13 @@ object TypeApplications { def unapply(tp: Type)(implicit ctx: Context): Option[(Type, List[Type])] = tp match { case TypeRef(prefix, tpnme.hkApply) => unapp(prefix) - case _ => unapp(tp) + case _ => + unapp(tp) match { + case Some((tycon: TypeRef, _)) if tycon.symbol.isLambdaTrait => + // We are seeing part of a lambda abstraction, not an applied type + None + case x => x + } } private def unapp(tp: Type)(implicit ctx: Context): Option[(Type, List[Type])] = tp match { diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 54e6397bb..b5d5c864b 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -1899,7 +1899,17 @@ object Types { override def underlying(implicit ctx: Context) = parent - private def checkInst(implicit ctx: Context): this.type = this + private def badInst = + throw new AssertionError(s"bad instantiation: $this") + + def checkInst(implicit ctx: Context): this.type = { + if (refinedName == tpnme.hkApply) + parent.stripTypeVar match { + case RefinedType(_, name) if name.isHkArgName => // ok + case _ => badInst + } + this + } def derivedRefinedType(parent: Type, refinedName: Name, refinedInfo: Type)(implicit ctx: Context): RefinedType = if ((parent eq this.parent) && (refinedName eq this.refinedName) && (refinedInfo eq this.refinedInfo)) this -- cgit v1.2.3