Skip to content

Commit ba16067

Browse files
jchybtgodzik
authored andcommitted
Make sure TypeBlocks are not incorrectly matched against Blocks
[Cherry-picked 71044a8]
1 parent 074e40e commit ba16067

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
@@ -805,7 +805,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
805805

806806
object BlockTypeTest extends TypeTest[Tree, Block]:
807807
def unapply(x: Tree): Option[Block & x.type] = x match
808-
case x: (tpd.Block & x.type) => Some(x)
808+
case x: (tpd.Block & x.type) if x.isTerm => Some(x)
809809
case _ => None
810810
end BlockTypeTest
811811

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)