aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Typer.scala12
-rw-r--r--tests/run/i1991.scala9
2 files changed, 14 insertions, 7 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala
index 820044b8e..498fd001b 100644
--- a/compiler/src/dotty/tools/dotc/typer/Typer.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala
@@ -1128,15 +1128,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
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}")
body1 match {
- case UnApply(fn, Nil, arg :: Nil) if tree.body.isInstanceOf[untpd.Typed] && !body1.tpe.isError =>
- // 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)
+ case UnApply(fn, Nil, arg :: Nil) if fn.symbol.owner == defn.ClassTagClass && !body1.tpe.isError =>
+ // A typed pattern `x @ (e: T)` with an implicit `ctag: ClassTag[T]`
+ // was rewritten to `x @ ctag(e)` by `tryWithClassTag`.
+ // Rewrite further to `ctag(x @ e)`
tpd.cpy.UnApply(body1)(fn, Nil,
- typed(untpd.Bind(tree.name, arg).withPos(tree.pos), arg.tpe) :: Nil)
+ typed(untpd.Bind(tree.name, untpd.TypedSplice(arg)).withPos(tree.pos), arg.tpe) :: Nil)
case _ =>
val sym = newPatternBoundSym(tree.name, body1.tpe, tree.pos)
assignType(cpy.Bind(tree)(tree.name, body1), sym)
diff --git a/tests/run/i1991.scala b/tests/run/i1991.scala
index 524a3f311..cec1dec89 100644
--- a/tests/run/i1991.scala
+++ b/tests/run/i1991.scala
@@ -10,6 +10,15 @@ class A[Foo](implicit tag: ClassTag[Foo]) {
//case foo: Foo => true
case _ => false
}
+
+ def testBind(x: Any) = x match {
+ case foo0: Foo =>
+ (foo0: Foo)
+ case foo1 @ (_: Foo) =>
+ (foo1: Foo)
+ case foo2 @ ExtractFoo() =>
+ (foo2: Foo)
+ }
}
object Test {