aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-03-21 18:17:26 +0100
committerMartin Odersky <odersky@gmail.com>2016-03-21 18:17:30 +0100
commit4df2e28a54978ee16e24bab961d9b491b6fe8707 (patch)
treec27b15c30014727a234804f7010be0cbf85ad28d /src/dotty/tools/dotc/typer/Typer.scala
parent1b29119b8ed1a2c3b382dfca01d6dde71f6ae733 (diff)
downloaddotty-4df2e28a54978ee16e24bab961d9b491b6fe8707.tar.gz
dotty-4df2e28a54978ee16e24bab961d9b491b6fe8707.tar.bz2
dotty-4df2e28a54978ee16e24bab961d9b491b6fe8707.zip
Fix problem involving classtag based pattern matches.
Rewriting did not go far enough, as evidenced by pos/i1174.scala Fixes #1174
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 8189f3c67..3b8ada2a8 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -842,7 +842,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
val proto2 = // the computed type of the `elemtpt` field
if (!tree.elemtpt.isEmpty) WildcardType
else if (isFullyDefined(proto1, ForceDegree.none)) proto1
- else if (tree.elems.isEmpty && tree.isInstanceOf[Trees.JavaSeqLiteral[_]])
+ else if (tree.elems.isEmpty && tree.isInstanceOf[Trees.JavaSeqLiteral[_]])
defn.ObjectType // generic empty Java varargs are of type Object[]
else ctx.typeComparer.lub(elems1.tpes)
val elemtpt1 = typed(tree.elemtpt, proto2)
@@ -961,13 +961,23 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
assignType(cpy.TypeBoundsTree(tree)(lo1, hi1), lo1, hi1)
}
- def typedBind(tree: untpd.Bind, pt: Type)(implicit ctx: Context): Bind = track("typedBind") {
+ def typedBind(tree: untpd.Bind, pt: Type)(implicit ctx: Context): Tree = track("typedBind") {
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)
+ body1 match {
+ case UnApply(fn, Nil, arg :: Nil) if tree.body.isInstanceOf[untpd.Typed] =>
+ // A typed pattern `x @ (_: T)` with an implicit `ctag: ClassTag[T]`
+ // was rewritten to `x @ ctag(_)`.
+ // Rewrite further to `ctag(x @ _)`
+ assert(fn.symbol.owner == defn.ClassTagClass)
+ tpd.cpy.UnApply(body1)(fn, Nil,
+ typed(untpd.Bind(tree.name, arg).withPos(tree.pos), arg.tpe) :: Nil)
+ case _ =>
+ 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)
+ }
}
def typedAlternative(tree: untpd.Alternative, pt: Type)(implicit ctx: Context): Alternative = track("typedAlternative") {