Skip to content

Fix quote match leak #8551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1234,12 +1234,15 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
override def inlineContext(call: Tree)(implicit ctx: Context): Context = {
// We assume enclosingInlineds is already normalized, and only process the new call with the head.
val oldIC = enclosingInlineds
val newIC = (call, oldIC) match {
case (t, t1 :: ts2) if t.isEmpty =>
assert(!t1.isEmpty)
ts2
case _ => call :: oldIC
}

val newIC =
if call.isEmpty then
oldIC match
case t1 :: ts2 => ts2
case _ => oldIC
else
call :: oldIC

ctx.fresh.setProperty(InlinedCalls, newIC)
}

Expand Down
7 changes: 5 additions & 2 deletions library/src/scala/internal/quoted/Matcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private[quoted] object Matcher {
if (hasTypeSplices) {
val ctx: Context = internal.Context_GADT_setFreshGADTBounds(rootContext)
given Context = ctx
val matchings = scrutineeTerm.underlyingArgument =?= patternTerm.underlyingArgument
val matchings = scrutineeTerm =?= patternTerm
// After matching and doing all subtype checks, we have to approximate all the type bindings
// that we have found and seal them in a quoted.Type
matchings.asOptionOfTuple.map { tup =>
Expand All @@ -44,7 +44,7 @@ private[quoted] object Matcher {
}
}
else {
scrutineeTerm.underlyingArgument =?= patternTerm.underlyingArgument
scrutineeTerm =?= patternTerm
}
}

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

case (NamedArg(name1, arg1), NamedArg(name2, arg2)) if name1 == name2 =>
arg1 =?= arg2

// No Match
case _ =>
if (debug)
Expand Down
2 changes: 2 additions & 0 deletions tests/run-macros/i6253-c.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ERROR
ERROR
21 changes: 21 additions & 0 deletions tests/run-macros/i6253-c/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import scala.quoted._


object Macros {

// Should be: inline def (inline self: StringContext) ...
inline def (self: => StringContext) xyz(args: => String*): String = ${impl('self, 'args)}

private def impl(self: Expr[StringContext], args: Expr[Seq[String]])(using QuoteContext): Expr[String] = {
self match {
case '{ StringContext($parts: _*) } =>
'{
val p: Seq[String] = $parts
val a: Seq[Any] = $args ++ Seq("")
p.zip(a).map(_ + _.toString).mkString
}
case _ =>
'{ "ERROR" }
}
}
}
10 changes: 10 additions & 0 deletions tests/run-macros/i6253-c/quoted_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Macros._

object Test {

def main(args: Array[String]): Unit = {
println(xyz"Hello World")
println(xyz"Hello ${"World"}")
}

}