diff options
author | Martin Odersky <odersky@gmail.com> | 2015-04-30 11:30:44 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-05-02 19:07:38 +0200 |
commit | 3df53946319d7f6c7af6e0eca757e548b6bc5cef (patch) | |
tree | 0cc0e7807395e2baad1a92cc9c92ca343d11099c | |
parent | 5cd90e5afd73c6f8354d0d3687fb2ee3a9f413e7 (diff) | |
download | dotty-3df53946319d7f6c7af6e0eca757e548b6bc5cef.tar.gz dotty-3df53946319d7f6c7af6e0eca757e548b6bc5cef.tar.bz2 dotty-3df53946319d7f6c7af6e0eca757e548b6bc5cef.zip |
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.
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 5 | ||||
-rw-r--r-- | tests/pos/Patterns.scala | 5 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index b58f48728..191a13ad0 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -844,8 +844,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } def typedBind(tree: untpd.Bind, pt: Type)(implicit ctx: Context): Bind = track("typedBind") { - val body1 = typed(tree.body, pt) - typr.println(i"typed bind $tree pt = $pt bodytpe = ${body1.tpe}") + val pt1 = fullyDefinedType(pt, "pattern variable", tree.pos) + val body1 = typed(tree.body, pt1) + typr.println(i"typed bind $tree pt = $pt1 bodytpe = ${body1.tpe}") val flags = if (tree.isType) BindDefinedType else EmptyFlags val sym = ctx.newSymbol(ctx.owner, tree.name, flags, body1.tpe, coord = tree.pos) assignType(cpy.Bind(tree)(tree.name, body1), sym) diff --git a/tests/pos/Patterns.scala b/tests/pos/Patterns.scala index e443c2ab5..e9bce87a9 100644 --- a/tests/pos/Patterns.scala +++ b/tests/pos/Patterns.scala @@ -94,3 +94,8 @@ object Patterns { t } } + +object NestedPattern { + val xss: List[List[String]] = ??? + val List(List(x)) = xss +} |