Skip to content

Commit cb208bf

Browse files
committed
Ignore types in macro runtime dependencies
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.
1 parent 924d35f commit cb208bf

File tree

7 files changed

+35
-3
lines changed

7 files changed

+35
-3
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
18821882
override def apply(syms: List[Symbol], tree: tpd.Tree)(using Context): List[Symbol] =
18831883
if level != -1 then foldOver(syms, tree)
18841884
else tree match {
1885-
case tree: RefTree if tree.symbol.isDefinedInCurrentRun && !tree.symbol.isLocal =>
1885+
case tree: RefTree if tree.isTerm && tree.symbol.isDefinedInCurrentRun && !tree.symbol.isLocal =>
18861886
foldOver(tree.symbol :: syms, tree)
18871887
case Quoted(body) =>
18881888
level += 1
@@ -1896,8 +1896,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
18961896
level -= 1
18971897
try apply(syms, body)
18981898
finally level += 1
1899-
case TypeApply(fun, _) =>
1900-
apply(syms, fun)
1899+
case _: TypTree =>
1900+
syms
19011901
case _ =>
19021902
foldOver(syms, tree)
19031903
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted.*
2+
3+
class Wrapper[T](t: T):
4+
inline def showType: String = ${ Wrapper.showTypeImpl[T]}
5+
6+
object Wrapper:
7+
def showTypeImpl[U](using Quotes): Expr[String] = Expr("foo")

tests/pos-macros/i12498a/Test_2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Person
2+
3+
def test = Wrapper(new Person).showType
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.quoted.*
2+
3+
4+
class Wrapper[T](t: T):
5+
inline def nothing: T = ${ Wrapper.nothing : Expr[T] }
6+
7+
object Wrapper:
8+
def nothing(using Quotes): Expr[Nothing] = '{???}

tests/pos-macros/i12498b/Test_2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Person
2+
3+
def test = Wrapper(new Person).nothing
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.quoted.*
2+
3+
4+
class Wrapper[T](t: T):
5+
inline def emptyList: List[T] = ${ Wrapper.emptyListImpl : Expr[List[T]] }
6+
7+
object Wrapper:
8+
def emptyListImpl(using Quotes): Expr[List[Nothing]] = Expr(Nil)

tests/pos-macros/i12498c/Test_2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Person
2+
3+
def test = Wrapper(new Person).emptyList

0 commit comments

Comments
 (0)