Skip to content

Commit d9df0a2

Browse files
Merge pull request scala#8551 from dotty-staging/fix-quote-match-leak
Fix quote match leak
2 parents a1350bb + 2e8fa8d commit d9df0a2

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,12 +1234,15 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
12341234
override def inlineContext(call: Tree)(implicit ctx: Context): Context = {
12351235
// We assume enclosingInlineds is already normalized, and only process the new call with the head.
12361236
val oldIC = enclosingInlineds
1237-
val newIC = (call, oldIC) match {
1238-
case (t, t1 :: ts2) if t.isEmpty =>
1239-
assert(!t1.isEmpty)
1240-
ts2
1241-
case _ => call :: oldIC
1242-
}
1237+
1238+
val newIC =
1239+
if call.isEmpty then
1240+
oldIC match
1241+
case t1 :: ts2 => ts2
1242+
case _ => oldIC
1243+
else
1244+
call :: oldIC
1245+
12431246
ctx.fresh.setProperty(InlinedCalls, newIC)
12441247
}
12451248

library/src/scala/internal/quoted/Matcher.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private[quoted] object Matcher {
3333
if (hasTypeSplices) {
3434
val ctx: Context = internal.Context_GADT_setFreshGADTBounds(rootContext)
3535
given Context = ctx
36-
val matchings = scrutineeTerm.underlyingArgument =?= patternTerm.underlyingArgument
36+
val matchings = scrutineeTerm =?= patternTerm
3737
// After matching and doing all subtype checks, we have to approximate all the type bindings
3838
// that we have found and seal them in a quoted.Type
3939
matchings.asOptionOfTuple.map { tup =>
@@ -44,7 +44,7 @@ private[quoted] object Matcher {
4444
}
4545
}
4646
else {
47-
scrutineeTerm.underlyingArgument =?= patternTerm.underlyingArgument
47+
scrutineeTerm =?= patternTerm
4848
}
4949
}
5050

@@ -286,6 +286,9 @@ private[quoted] object Matcher {
286286
case (_, Annotated(tpt, _)) =>
287287
scrutinee =?= tpt
288288

289+
case (NamedArg(name1, arg1), NamedArg(name2, arg2)) if name1 == name2 =>
290+
arg1 =?= arg2
291+
289292
// No Match
290293
case _ =>
291294
if (debug)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import scala.quoted._
2+
3+
4+
object Macros {
5+
6+
// Should be: inline def (inline self: StringContext) ...
7+
inline def (self: => StringContext) xyz(args: => String*): String = ${impl('self, 'args)}
8+
9+
private def impl(self: Expr[StringContext], args: Expr[Seq[String]])(using QuoteContext): Expr[String] = {
10+
self match {
11+
case '{ StringContext($parts: _*) } => // Should not match as the parameter is not marked as inlined
12+
'{ ??? }
13+
case _ =>
14+
'{ "Ok" }
15+
}
16+
}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Macros._
2+
3+
object Test {
4+
5+
def main(args: Array[String]): Unit = {
6+
println(xyz"Hello World")
7+
println(xyz"Hello ${"World"}")
8+
}
9+
10+
}

0 commit comments

Comments
 (0)