Skip to content

Only transform the body of the quote with QuoteTransformer #17451

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
May 10, 2023
Merged
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
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/Splicing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ class Splicing extends MacroTransform:
override def transform(tree: tpd.Tree)(using Context): tpd.Tree =
assert(level == 0)
tree match
case Apply(Select(_: Quote, nme.apply), _) =>
QuoteTransformer().transform(tree)
case tree: Quote =>
val body1 = QuoteTransformer().transform(tree.body)(using quoteContext)
cpy.Quote(tree)(body = body1)
case tree: DefDef if tree.symbol.is(Inline) =>
// Quotes in inlined methods are only pickled after they are inlined.
Copy link
Member

Choose a reason for hiding this comment

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

What happens if I have a quote in an inline def in a class in a quote? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume you mean something like

'{
  class Foo:
    inline def f = '{ ... }
}

In that case the inline def should be rejected when typing. I will check that this is correctly handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We fail correctly with

5 |    inline def f(using Quotes) = '{ 1 }
  |               ^
  |               inline def cannot be within quotes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tree
case _ =>
super.transform(tree)
end Level0QuoteTransformer


/** Transforms all direct splices in the current quote and replace them with holes. */
private class QuoteTransformer() extends Transformer:
/** Set of definitions in the current quote */
Expand All @@ -108,6 +108,7 @@ class Splicing extends MacroTransform:
private val typeHoles = mutable.Map.empty[TermRef, Hole]

override def transform(tree: tpd.Tree)(using Context): tpd.Tree =
assert(level > 0)
tree match
case tree: Splice if level == 1 =>
val holeIdx = numHoles
Expand Down