From 072af0012ac10b5d24d91954911825be543a6517 Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Wed, 7 Dec 2016 23:09:06 +0100 Subject: [PATCH] fix #1773: handle patterns in interpolated string --- compiler/src/dotty/tools/dotc/ast/Desugar.scala | 6 ++++++ tests/run/i1773.check | 2 ++ tests/run/i1773.scala | 14 ++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 tests/run/i1773.check create mode 100644 tests/run/i1773.scala diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index c8b1ed909967..7f25d6b0c5f6 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -916,7 +916,11 @@ object desugar { val elems = segments flatMap { case ts: Thicket => ts.trees.tail case t => Nil + } map { + case Block(Nil, expr) => expr // important for interpolated string as patterns, see i1773.scala + case t => t } + Apply(Select(Apply(Ident(nme.StringContext), strs), id), elems) case InfixOp(l, op, r) => if (ctx.mode is Mode.Type) @@ -1081,6 +1085,8 @@ object desugar { trees foreach collect case Thicket(trees) => trees foreach collect + case Block(Nil, expr) => + collect(expr) case _ => } collect(tree) diff --git a/tests/run/i1773.check b/tests/run/i1773.check new file mode 100644 index 000000000000..888299747af9 --- /dev/null +++ b/tests/run/i1773.check @@ -0,0 +1,2 @@ +class + extends diff --git a/tests/run/i1773.scala b/tests/run/i1773.scala new file mode 100644 index 000000000000..82fa0dfb4e74 --- /dev/null +++ b/tests/run/i1773.scala @@ -0,0 +1,14 @@ +object Test { + implicit class Foo(sc: StringContext) { + object q { + def unapply(arg: Any): Option[(Any, Any)] = + Some((sc.parts(0), sc.parts(1))) + } + } + + def main(args: Array[String]): Unit = { + val q"class ${name: String} extends ${parent: String}" = new Object + println(name) + println(parent) + } +}