diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index ce8d19aae46a..237ab8448fd4 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -1413,7 +1413,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler object TypeBlockTypeTest extends TypeTest[Tree, TypeBlock]: def unapply(x: Tree): Option[TypeBlock & x.type] = x match - case tpt: (tpd.Block & x.type) => Some(tpt) + case tpt: (tpd.Block & x.type) if x.isType => Some(tpt) case _ => None end TypeBlockTypeTest diff --git a/tests/pos/i21721/Macro.scala b/tests/pos/i21721/Macro.scala new file mode 100644 index 000000000000..dfdbff6a659b --- /dev/null +++ b/tests/pos/i21721/Macro.scala @@ -0,0 +1,12 @@ +import quoted.* + +object Macro: + inline def impl(inline expr: Any): Any = + ${implImpl('expr)} + + def implImpl(expr: Expr[Any])(using q: Quotes): Expr[Any] = + import q.reflect.* + expr.asTerm.asInstanceOf[Inlined].body match + // this should not fail with a MatchError + case TypeBlock(_, _) => '{ "TypeBlock" } + case _ => '{ "Nothing" } diff --git a/tests/pos/i21721/Test.scala b/tests/pos/i21721/Test.scala new file mode 100644 index 000000000000..ebe91bae9ef4 --- /dev/null +++ b/tests/pos/i21721/Test.scala @@ -0,0 +1,5 @@ +object Test: + // give a Block(...) to the macro + Macro.impl: + val a = 3 + a