aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliu fengyun <liufengyunchina@gmail.com>2016-12-08 19:43:44 +0100
committerGitHub <noreply@github.com>2016-12-08 19:43:44 +0100
commitac160ea20dc3a18cad33484286cb3e37e9fe1171 (patch)
treea4333c83ef1f9a13322ccda0c8394563dcedf84c
parent9fcc0a2b818feea2f6205fe1fe27cdc4e518bcbd (diff)
parent072af0012ac10b5d24d91954911825be543a6517 (diff)
downloaddotty-ac160ea20dc3a18cad33484286cb3e37e9fe1171.tar.gz
dotty-ac160ea20dc3a18cad33484286cb3e37e9fe1171.tar.bz2
dotty-ac160ea20dc3a18cad33484286cb3e37e9fe1171.zip
Merge pull request #1778 from dotty-staging/fix-i1773
Fix #1773: handle patterns in interpolated string
-rw-r--r--compiler/src/dotty/tools/dotc/ast/Desugar.scala6
-rw-r--r--tests/run/i1773.check2
-rw-r--r--tests/run/i1773.scala14
3 files changed, 22 insertions, 0 deletions
diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala
index c8b1ed909..7f25d6b0c 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 000000000..888299747
--- /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 000000000..82fa0dfb4
--- /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)
+ }
+}