diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index 389fe82c2732..9c12715b1602 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -150,6 +150,9 @@ object Inferencing { tree } + def isSkolemFree(tp: Type)(implicit ctx: Context): Boolean = + !tp.existsPart(_.isInstanceOf[SkolemType]) + /** Derive information about a pattern type by comparing it with some variant of the * static scrutinee type. We have the following situation in case of a (dynamic) pattern match: * diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 40e4cc82f4e5..1cf2246a35e5 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -520,6 +520,7 @@ class Typer extends Namer def isEligible(tp: Type) = tp.exists && !tp.typeSymbol.is(Final) && !tp.isRef(defn.AnyClass) if (templ1.parents.isEmpty && isFullyDefined(pt, ForceDegree.noBottom) && + isSkolemFree(pt) && isEligible(pt.underlyingClassRef(refinementOK = false))) templ1 = cpy.Template(templ)(parents = untpd.TypeTree(pt) :: Nil) templ1.parents foreach { diff --git a/tests/neg/i6036.scala b/tests/neg/i6036.scala new file mode 100644 index 000000000000..156029a994a8 --- /dev/null +++ b/tests/neg/i6036.scala @@ -0,0 +1,9 @@ +class A { class AProxy } + +object B { + inline def head(a: A)(code: => a.AProxy): Unit = code + head(new A)(new {}) // error: found: Object {...} required: ?1.AProxy + + val a = new A + head(a)(new a.AProxy{}) // ok +} \ No newline at end of file