Skip to content

Commit d2dcddf

Browse files
committed
Make sure types of pattern bound variables are fully-defined.
Like all other variables, pattern-bound vars need a fully defined type. I was thinking originally that demanding a fully defined selector type is sufficient to ensure this, but that's not true: An outer pattern might call a polymorphic unapply and its type variables need not be fully instantiated. With the fix, the minimized test case from ExpandSAMs works.
1 parent 266234c commit d2dcddf

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
844844
}
845845

846846
def typedBind(tree: untpd.Bind, pt: Type)(implicit ctx: Context): Bind = track("typedBind") {
847-
val body1 = typed(tree.body, pt)
848-
typr.println(i"typed bind $tree pt = $pt bodytpe = ${body1.tpe}")
847+
val pt1 = fullyDefinedType(pt, "pattern variable", tree.pos)
848+
val body1 = typed(tree.body, pt1)
849+
typr.println(i"typed bind $tree pt = $pt1 bodytpe = ${body1.tpe}")
849850
val flags = if (tree.isType) BindDefinedType else EmptyFlags
850851
val sym = ctx.newSymbol(ctx.owner, tree.name, flags, body1.tpe, coord = tree.pos)
851852
assignType(cpy.Bind(tree)(tree.name, body1), sym)

tests/pos/Patterns.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,8 @@ object Patterns {
9494
t
9595
}
9696
}
97+
98+
object NestedPattern {
99+
val xss: List[List[String]] = ???
100+
val List(List(x)) = xss
101+
}

0 commit comments

Comments
 (0)