Skip to content

Commit fe88a3b

Browse files
Dealias types in New before matching quotes (#17615)
Fixes #17606
2 parents 8814760 + f453727 commit fe88a3b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ object QuoteMatcher {
354354
/* Match new */
355355
case New(tpt1) =>
356356
pattern match
357-
case New(tpt2) if tpt1.tpe.typeSymbol == tpt2.tpe.typeSymbol => matched
357+
case New(tpt2) if tpt1.tpe.dealias.typeSymbol == tpt2.tpe.dealias.typeSymbol => matched
358358
case _ => notMatched
359359

360360
/* Match this */
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package example
2+
3+
import scala.quoted.*
4+
5+
object A {
6+
inline def f(inline a: Any): Boolean = ${ impl('a) }
7+
8+
def impl(a: Expr[Any])(using Quotes): Expr[Boolean] = {
9+
a match {
10+
case '{ new String($x: Array[Byte]) } => Expr(true)
11+
case _ => quotes.reflect.report.errorAndAbort("Expected match", a)
12+
}
13+
}
14+
}

tests/pos-macros/i17606/Test_2.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package example
2+
3+
object Main {
4+
def main(args: Array[String]): Unit = {
5+
val x = A.f(new String(Array.empty[Byte]))
6+
println(x)
7+
}
8+
}

0 commit comments

Comments
 (0)