Skip to content

Commit 8477394

Browse files
committed
Avoid false positives when extracting AppliedType
1 parent 9fbffdc commit 8477394

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ object TypeApplications {
133133

134134
def unapply(tp: Type)(implicit ctx: Context): Option[(Type, List[Type])] = tp match {
135135
case TypeRef(prefix, tpnme.hkApply) => unapp(prefix)
136-
case _ => unapp(tp)
136+
case _ =>
137+
unapp(tp) match {
138+
case Some((tycon: TypeRef, _)) if tycon.symbol.isLambdaTrait =>
139+
// We are seeing part of a lambda abstraction, not an applied type
140+
None
141+
case x => x
142+
}
137143
}
138144

139145
private def unapp(tp: Type)(implicit ctx: Context): Option[(Type, List[Type])] = tp match {

src/dotty/tools/dotc/core/Types.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,17 @@ object Types {
18991899

19001900
override def underlying(implicit ctx: Context) = parent
19011901

1902-
private def checkInst(implicit ctx: Context): this.type = this
1902+
private def badInst =
1903+
throw new AssertionError(s"bad instantiation: $this")
1904+
1905+
def checkInst(implicit ctx: Context): this.type = {
1906+
if (refinedName == tpnme.hkApply)
1907+
parent.stripTypeVar match {
1908+
case RefinedType(_, name) if name.isHkArgName => // ok
1909+
case _ => badInst
1910+
}
1911+
this
1912+
}
19031913

19041914
def derivedRefinedType(parent: Type, refinedName: Name, refinedInfo: Type)(implicit ctx: Context): RefinedType =
19051915
if ((parent eq this.parent) && (refinedName eq this.refinedName) && (refinedInfo eq this.refinedInfo)) this

0 commit comments

Comments
 (0)