Skip to content

Commit 1128509

Browse files
authored
Merge pull request #282 from scala/backport-lts-3.3-22716
Backport "Make sure Block does not incorrectly match a TypeBlock" to 3.3 LTS
2 parents acf46f9 + ba16067 commit 1128509

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-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
@@ -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.
Lines changed: 11 additions & 0 deletions
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
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@main def Test() = test()

0 commit comments

Comments
 (0)