Skip to content

Commit 71044a8

Browse files
committed
Make sure TypeBlocks are not incorrectly matched against Blocks
1 parent bef520f commit 71044a8

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

Diff for: 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.

Diff for: tests/pos-macros/i21721-b/Macro_1.scala

+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

Diff for: tests/pos-macros/i21721-b/Test_2.scala

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@main def Test() = test()

0 commit comments

Comments
 (0)