diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 172b3a35aabb..a666feace741 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -805,7 +805,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler object BlockTypeTest extends TypeTest[Tree, Block]: def unapply(x: Tree): Option[Block & x.type] = x match - case x: (tpd.Block & x.type) => Some(x) + case x: (tpd.Block & x.type) if x.isTerm => Some(x) case _ => None end BlockTypeTest diff --git a/tests/pos/i21721/Macro.scala b/tests/pos-macros/i21721-a/Macro.scala similarity index 100% rename from tests/pos/i21721/Macro.scala rename to tests/pos-macros/i21721-a/Macro.scala diff --git a/tests/pos/i21721/Test.scala b/tests/pos-macros/i21721-a/Test.scala similarity index 100% rename from tests/pos/i21721/Test.scala rename to tests/pos-macros/i21721-a/Test.scala diff --git a/tests/pos-macros/i21721-b/Macro_1.scala b/tests/pos-macros/i21721-b/Macro_1.scala new file mode 100644 index 000000000000..aad7d6232c8f --- /dev/null +++ b/tests/pos-macros/i21721-b/Macro_1.scala @@ -0,0 +1,11 @@ +import scala.quoted._ + +inline def test(): Any = ${ testImpl } + +def testImpl(using Quotes): Expr[Any] = + import quotes.reflect._ + TypeBlock(Nil, TypeTree.of[Int]) match + case Block(_, res) => + res.asExpr // unexpected case - would crash here, as res of TypeBlock is not a term + case _ => + '{()} // expected case diff --git a/tests/pos-macros/i21721-b/Test_2.scala b/tests/pos-macros/i21721-b/Test_2.scala new file mode 100644 index 000000000000..9b75f0ca5777 --- /dev/null +++ b/tests/pos-macros/i21721-b/Test_2.scala @@ -0,0 +1 @@ +@main def Test() = test()