diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index 97f14e2fe5a4..8541ec26af49 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -503,7 +503,7 @@ object Inferencing { * $i is a skolem of type `scala.internal.TypeBox`, and `CAP` is its * type member. See the documentation of `TypeBox` for a rationale why we do this. */ - def captureWildcards(tp: Type)(using Context): Type = tp match { + def captureWildcards(tp: Type)(using Context): Type = tp.dealias match { case tp @ AppliedType(tycon, args) if tp.hasWildcardArg => tycon.typeParams match { case tparams @ ((_: Symbol) :: _) => diff --git a/tests/pos/i12739.scala b/tests/pos/i12739.scala new file mode 100644 index 000000000000..0411c6f02c91 --- /dev/null +++ b/tests/pos/i12739.scala @@ -0,0 +1,16 @@ +object O { + + class CA[A](var x: A) + type C = CA[_] + + val c: C = ??? + def f[A](r: CA[A]): A = r.x + + def g(): CA[_] = CA("hello") + + f(g()) + f(c) + f(c.asInstanceOf[CA[_]]) + f(c.asInstanceOf[C]) + f(c.asInstanceOf[c.type]) +}