Skip to content

Commit 63f6a46

Browse files
committed
Fix #9632: Don't use inDefScopeBraces for staged blocks
inDefScopeBraces blocks can be rewritten, but that would give illegal code for staged blocks.
1 parent 93f24a0 commit 63f6a46

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,10 @@ object Parsers {
15661566
else t
15671567

15681568
/** The block in a quote or splice */
1569-
def stagedBlock() = inDefScopeBraces(block(simplify = true))
1569+
def stagedBlock() =
1570+
val saved = lastStatOffset
1571+
try inBraces(block(simplify = true))
1572+
finally lastStatOffset = saved
15701573

15711574
/** SimpleEpxr ::= spliceId | ‘$’ ‘{’ Block ‘}’)
15721575
* SimpleType ::= spliceId | ‘$’ ‘{’ Block ‘}’)

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class CompilationTests {
6666

6767
aggregateTests(
6868
compileFile("tests/rewrites/rewrites.scala", scala2CompatMode.and("-rewrite", "-indent")),
69-
compileFile("tests/rewrites/i8982.scala", defaultOptions.and("-indent", "-rewrite"))
69+
compileFile("tests/rewrites/i8982.scala", defaultOptions.and("-indent", "-rewrite")),
70+
compileFile("tests/rewrites/i9632.scala", defaultOptions.and("-indent", "-rewrite"))
7071
).checkRewrites()
7172
}
7273

tests/rewrites/i9632.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def f(using scala.quoted.QuoteContext) =
2+
'{
3+
val x = ${
4+
???
5+
}
6+
x
7+
}

0 commit comments

Comments
 (0)