Skip to content

Commit

Permalink
Ignore types in macro runtime dependencies
Browse files Browse the repository at this point in the history
We can have different kinds of type references in the contents of a
splice. We do not care about types because those are erased and the
interpreter emulates erased semantics. These types are in `Tree`s that
extend `TypeTree` or `RefTree` referring to type.

Fixes #12498
  • Loading branch information
nicolasstucki committed Jul 4, 2022
1 parent 7d6d42f commit 7ccd826
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 2 deletions.
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1046,9 +1046,9 @@ class Inliner(val call: tpd.Tree)(using Context):
new TreeAccumulator[List[Symbol]] {
private var level = -1
override def apply(syms: List[Symbol], tree: tpd.Tree)(using Context): List[Symbol] =
if (level != -1) foldOver(syms, tree)
if level != -1 then foldOver(syms, tree)
else tree match {
case tree: RefTree if level == -1 && tree.symbol.isDefinedInCurrentRun && !tree.symbol.isLocal =>
case tree: RefTree if tree.isTerm && tree.symbol.isDefinedInCurrentRun && !tree.symbol.isLocal =>
foldOver(tree.symbol :: syms, tree)
case Quoted(body) =>
level += 1
Expand All @@ -1062,6 +1062,8 @@ class Inliner(val call: tpd.Tree)(using Context):
level -= 1
try apply(syms, body)
finally level += 1
case _: TypTree =>
syms
case _ =>
foldOver(syms, tree)
}
Expand Down
7 changes: 7 additions & 0 deletions tests/pos-macros/i12498/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted.*

class Wrapper[T](t: T):
inline def showType: String = ${ Wrapper.showTypeImpl[T]}

object Wrapper:
def showTypeImpl[U](using Quotes): Expr[String] = Expr("foo")
3 changes: 3 additions & 0 deletions tests/pos-macros/i12498/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Person

def test = Wrapper(new Person).showType
7 changes: 7 additions & 0 deletions tests/pos-macros/i12498a/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted.*

class Wrapper[T](t: T):
inline def showType: String = ${ Wrapper.showTypeImpl[T]}

object Wrapper:
def showTypeImpl[U](using Quotes): Expr[String] = Expr("foo")
3 changes: 3 additions & 0 deletions tests/pos-macros/i12498a/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Person

def test = Wrapper(new Person).showType
8 changes: 8 additions & 0 deletions tests/pos-macros/i12498b/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import scala.quoted.*


class Wrapper[T](t: T):
inline def nothing: T = ${ Wrapper.nothing : Expr[T] }

object Wrapper:
def nothing(using Quotes): Expr[Nothing] = '{???}
3 changes: 3 additions & 0 deletions tests/pos-macros/i12498b/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Person

def test = Wrapper(new Person).nothing
8 changes: 8 additions & 0 deletions tests/pos-macros/i12498c/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import scala.quoted.*


class Wrapper[T](t: T):
inline def emptyList: List[T] = ${ Wrapper.emptyListImpl : Expr[List[T]] }

object Wrapper:
def emptyListImpl(using Quotes): Expr[List[Nothing]] = Expr(Nil)
3 changes: 3 additions & 0 deletions tests/pos-macros/i12498c/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Person

def test = Wrapper(new Person).emptyList

0 comments on commit 7ccd826

Please sign in to comment.