Skip to content

Cancel quotes while inlining #12193

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 1 commit into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,11 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
super.typedValDef(vdef1, sym)

override def typedApply(tree: untpd.Apply, pt: Type)(using Context): Tree =
val res = constToLiteral(betaReduce(super.typedApply(tree, pt))) match {
def cancelQuotes(tree: Tree): Tree =
tree match
case Quoted(Spliced(inner)) => inner
case _ => tree
val res = cancelQuotes(constToLiteral(betaReduce(super.typedApply(tree, pt)))) match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix failed the following code:

inline def test[T](inline t: T): T = ${ identity('{ identity(${ identity('{ identity(${ identity('t) }) }) }) }) }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a different problem. I will open an issue for it. See #12225.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this one:

inline def test[T](inline t: T): T = ${ '{ ${ '{ ${ 't } } } } }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That one works. Added it as a regression test.

case res: Apply if res.symbol == defn.QuotedRuntime_exprSplice
&& level == 0
&& !hasInliningErrors =>
Expand Down
7 changes: 7 additions & 0 deletions tests/pos-macros/i12173.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object TestMacro {
inline def test[T](inline t: T): T = ${ '{ ${ 't } } }
}

object Test {
TestMacro.test("x")
}
7 changes: 7 additions & 0 deletions tests/pos-macros/i12173b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object TestMacro {
inline def test[T](inline t: T): T = ${ '{ ${ '{ ${ 't } } } } }
}

object Test {
TestMacro.test("x")
}
7 changes: 7 additions & 0 deletions tests/pos-macros/i12173c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object TestMacro {
inline def test[T](inline t: T): T = ${ '{ ${ '{ ${ '{ ${ '{ ${ '{ ${ '{ ${ '{ ${ 't } } } } } } } } } } } } } } }
}

object Test {
TestMacro.test("x")
}