Skip to content

Commit

Permalink
Dealias types in New before matching quotes (#17615)
Browse files Browse the repository at this point in the history
Fixes #17606
  • Loading branch information
nicolasstucki authored Jun 2, 2023
2 parents 8814760 + f453727 commit fe88a3b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ object QuoteMatcher {
/* Match new */
case New(tpt1) =>
pattern match
case New(tpt2) if tpt1.tpe.typeSymbol == tpt2.tpe.typeSymbol => matched
case New(tpt2) if tpt1.tpe.dealias.typeSymbol == tpt2.tpe.dealias.typeSymbol => matched
case _ => notMatched

/* Match this */
Expand Down
14 changes: 14 additions & 0 deletions tests/pos-macros/i17606/Macros_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package example

import scala.quoted.*

object A {
inline def f(inline a: Any): Boolean = ${ impl('a) }

def impl(a: Expr[Any])(using Quotes): Expr[Boolean] = {
a match {
case '{ new String($x: Array[Byte]) } => Expr(true)
case _ => quotes.reflect.report.errorAndAbort("Expected match", a)
}
}
}
8 changes: 8 additions & 0 deletions tests/pos-macros/i17606/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package example

object Main {
def main(args: Array[String]): Unit = {
val x = A.f(new String(Array.empty[Byte]))
println(x)
}
}

0 comments on commit fe88a3b

Please sign in to comment.