Skip to content

Commit 332fceb

Browse files
authored
Make sure Block does not incorrectly match a TypeBlock (#22716)
Part 2 to #21722 We do the same thing as there, but this time to make sure TypeBlocks are not matched as Blocks. The tests from that PR were also moved, as I did not realize they were put in `tests/pos` instead of `tests/pos-macros` when making the review.
2 parents 4a85e27 + 71044a8 commit 332fceb

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
824824

825825
object BlockTypeTest extends TypeTest[Tree, Block]:
826826
def unapply(x: Tree): Option[Block & x.type] = x match
827-
case x: (tpd.Block & x.type) => Some(x)
827+
case x: (tpd.Block & x.type) if x.isTerm => Some(x)
828828
case _ => None
829829
end BlockTypeTest
830830

File renamed without changes.
File renamed without changes.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.quoted._
2+
3+
inline def test(): Any = ${ testImpl }
4+
5+
def testImpl(using Quotes): Expr[Any] =
6+
import quotes.reflect._
7+
TypeBlock(Nil, TypeTree.of[Int]) match
8+
case Block(_, res) =>
9+
res.asExpr // unexpected case - would crash here, as res of TypeBlock is not a term
10+
case _ =>
11+
'{()} // expected case
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@main def Test() = test()

0 commit comments

Comments
 (0)