Skip to content

Commit 1f45c3b

Browse files
committed
Fix #12739: Handle type alias in capturing wildcards
1 parent fcd837a commit 1f45c3b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ object Inferencing {
503503
* $i is a skolem of type `scala.internal.TypeBox`, and `CAP` is its
504504
* type member. See the documentation of `TypeBox` for a rationale why we do this.
505505
*/
506-
def captureWildcards(tp: Type)(using Context): Type = tp match {
506+
def captureWildcards(tp: Type)(using Context): Type = tp.dealias match {
507507
case tp @ AppliedType(tycon, args) if tp.hasWildcardArg =>
508508
tycon.typeParams match {
509509
case tparams @ ((_: Symbol) :: _) =>

tests/pos/i12739.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
object O {
2+
3+
class CA[A](var x: A)
4+
type C = CA[_]
5+
6+
val c: C = ???
7+
def f[A](r: CA[A]): A = r.x
8+
9+
def g(): CA[_] = CA("hello")
10+
11+
f(g())
12+
f(c)
13+
f(c.asInstanceOf[CA[_]])
14+
f(c.asInstanceOf[C])
15+
f(c.asInstanceOf[c.type])
16+
}

0 commit comments

Comments
 (0)