Skip to content

Commit 169bde6

Browse files
committed
wip
1 parent 48da272 commit 169bde6

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,10 @@ class Typer extends Namer
14131413
}
14141414

14151415
def typedBind(tree: untpd.Bind, pt: Type)(implicit ctx: Context): Tree = track("typedBind") {
1416+
if (ctx.mode.is(Mode.QuotedPattern) && tree.name.startsWith("$")) {
1417+
val bind1 = untpd.cpy.Bind(tree)(tree.name.toString.substring(1).toTermName, tree.body)
1418+
return typed(untpd.Apply(untpd.ref(defn.InternalQuoted_patternMatchBindHoleModuleR), bind1 :: Nil).withSpan(tree.span), pt)
1419+
}
14161420
val pt1 = fullyDefinedType(pt, "pattern variable", tree.span)
14171421
val body1 = typed(tree.body, pt1)
14181422
body1 match {
@@ -1976,7 +1980,7 @@ class Typer extends Namer
19761980
finally patBuf += pat
19771981
case tree @ UnApply(_, _, (bind: Bind) :: Nil) if tree.fun.symbol == defn.InternalQuoted_patternMatchBindHole_unapply =>
19781982
patBuf += bindExpr(bind.name, bind.tpe.widen, bind.span)
1979-
super.transform(tree)
1983+
cpy.UnApply(tree)(patterns = untpd.Ident(nme.WILDCARD).withType(bind.tpe.widen) :: Nil)
19801984
case vdef: ValDef if vdef.symbol.annotations.exists(_.symbol == defn.InternalQuoted_patternBindHoleAnnot) =>
19811985
patBuf += bindExpr(vdef.name, vdef.tpt.tpe, vdef.span)
19821986
super.transform(tree)
@@ -1986,15 +1990,6 @@ class Typer extends Namer
19861990
}
19871991

19881992
val result = splitter.transform(quoted)
1989-
println()
1990-
println(quoted.show)
1991-
println()
1992-
println(result.show)
1993-
println()
1994-
println(splitter.patBuf.toList)
1995-
println()
1996-
println()
1997-
println()
19981993
(result, splitter.patBuf.toList)
19991994
}
20001995

tests/pos/quotedPatterns.scala

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@ object Test {
66
def g(x: Int, y: Int) = x * y
77

88
def res given tasty.Reflection: quoted.Expr[Int] = x match {
9-
case '{1 + 2} => '{0}
10-
case '{f($y)} => y
11-
case '{g($y, $z)} => '{$y * $z}
12-
case '{ ((a: Int) => 3)($y) } => y
13-
case '{ 1 + ($y: Int)} => y
14-
case '{ val a = 1 + ($y: Int); 3 } => y
15-
// currently gives an unreachable case warning
16-
// but only when used in conjunction with the others.
17-
// I believe this is because implicit arguments are not taken
18-
// into account when checking whether we have already seen an `unapply` before.
19-
case '{ val $y: Int = $z; 1 } => z
20-
// TODO do NOT support syntax this syntax
21-
case '{ ((`$y`: Int) => 1 + y + ($z: Int))(2) } => z
9+
// case '{1 + 2} => '{0}
10+
// case '{f($y)} => y
11+
// case '{g($y, $z)} => '{$y * $z}
12+
// case '{ ((a: Int) => 3)($y) } => y
13+
// case '{ 1 + ($y: Int)} => y
14+
// case '{ val a = 1 + ($y: Int); 3 } => y
15+
// // currently gives an unreachable case warning
16+
// // but only when used in conjunction with the others.
17+
// // I believe this is because implicit arguments are not taken
18+
// // into account when checking whether we have already seen an `unapply` before.
19+
// case '{ val $y: Int = $z; 1 } => z
20+
// // TODO do NOT support syntax this syntax
21+
// case '{ ((`$y`: Int) => 1 + y + ($z: Int))(2) } => z
2222
// TODO support syntax this syntax
2323
// case '{ (($y: Int) => 1 + y + ($z: Int))(2) } => z
24-
case '{ Option(1) match { case Some($n) => $z } } => z
24+
// case '{ Option(1) match { case Some($n) => $z } } => z
25+
case '{ Option(1) match { case $a @ Some($n) => $z } } => z
26+
case '{ Option(1) match { case $b: Some[_] => $z } } => z
27+
case '{ Option(1) match { case $c => $z } } => z
2528
case _ => '{1}
2629
}
2730
}

0 commit comments

Comments
 (0)