Skip to content

Commit bc573a8

Browse files
authored
Merge pull request #278 from scala/backport-lts-3.3-21722
Backport "Fix scala#21721: make case TypeBlock(_, _) not match non-type Block" to 3.3 LTS
2 parents 55d8d63 + 8e6a37d commit bc573a8

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
13901390

13911391
object TypeBlockTypeTest extends TypeTest[Tree, TypeBlock]:
13921392
def unapply(x: Tree): Option[TypeBlock & x.type] = x match
1393-
case tpt: (tpd.Block & x.type) => Some(tpt)
1393+
case tpt: (tpd.Block & x.type) if x.isType => Some(tpt)
13941394
case _ => None
13951395
end TypeBlockTypeTest
13961396

tests/pos/i21721/Macro.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import quoted.*
2+
3+
object Macro:
4+
inline def impl(inline expr: Any): Any =
5+
${implImpl('expr)}
6+
7+
def implImpl(expr: Expr[Any])(using q: Quotes): Expr[Any] =
8+
import q.reflect.*
9+
expr.asTerm.asInstanceOf[Inlined].body match
10+
// this should not fail with a MatchError
11+
case TypeBlock(_, _) => '{ "TypeBlock" }
12+
case _ => '{ "Nothing" }

tests/pos/i21721/Test.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test:
2+
// give a Block(...) to the macro
3+
Macro.impl:
4+
val a = 3
5+
a

0 commit comments

Comments
 (0)