Skip to content

Commit 072af00

Browse files
committed
fix #1773: handle patterns in interpolated string
1 parent 9ceed92 commit 072af00

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,11 @@ object desugar {
916916
val elems = segments flatMap {
917917
case ts: Thicket => ts.trees.tail
918918
case t => Nil
919+
} map {
920+
case Block(Nil, expr) => expr // important for interpolated string as patterns, see i1773.scala
921+
case t => t
919922
}
923+
920924
Apply(Select(Apply(Ident(nme.StringContext), strs), id), elems)
921925
case InfixOp(l, op, r) =>
922926
if (ctx.mode is Mode.Type)
@@ -1081,6 +1085,8 @@ object desugar {
10811085
trees foreach collect
10821086
case Thicket(trees) =>
10831087
trees foreach collect
1088+
case Block(Nil, expr) =>
1089+
collect(expr)
10841090
case _ =>
10851091
}
10861092
collect(tree)

tests/run/i1773.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class
2+
extends

tests/run/i1773.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object Test {
2+
implicit class Foo(sc: StringContext) {
3+
object q {
4+
def unapply(arg: Any): Option[(Any, Any)] =
5+
Some((sc.parts(0), sc.parts(1)))
6+
}
7+
}
8+
9+
def main(args: Array[String]): Unit = {
10+
val q"class ${name: String} extends ${parent: String}" = new Object
11+
println(name)
12+
println(parent)
13+
}
14+
}

0 commit comments

Comments
 (0)