Skip to content

Commit dc5a9a4

Browse files
Merge pull request #15529 from dotty-staging/fix-#12498
Ignore types in macro runtime dependencies
2 parents fd0bfdc + 7ccd826 commit dc5a9a4

File tree

9 files changed

+46
-2
lines changed

9 files changed

+46
-2
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1046,9 +1046,9 @@ class Inliner(val call: tpd.Tree)(using Context):
10461046
new TreeAccumulator[List[Symbol]] {
10471047
private var level = -1
10481048
override def apply(syms: List[Symbol], tree: tpd.Tree)(using Context): List[Symbol] =
1049-
if (level != -1) foldOver(syms, tree)
1049+
if level != -1 then foldOver(syms, tree)
10501050
else tree match {
1051-
case tree: RefTree if level == -1 && tree.symbol.isDefinedInCurrentRun && !tree.symbol.isLocal =>
1051+
case tree: RefTree if tree.isTerm && tree.symbol.isDefinedInCurrentRun && !tree.symbol.isLocal =>
10521052
foldOver(tree.symbol :: syms, tree)
10531053
case Quoted(body) =>
10541054
level += 1
@@ -1062,6 +1062,8 @@ class Inliner(val call: tpd.Tree)(using Context):
10621062
level -= 1
10631063
try apply(syms, body)
10641064
finally level += 1
1065+
case _: TypTree =>
1066+
syms
10651067
case _ =>
10661068
foldOver(syms, tree)
10671069
}

tests/pos-macros/i12498/Macro_1.scala

+7
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/i12498/Test_2.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Person
2+
3+
def test = Wrapper(new Person).showType
+7
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

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Person
2+
3+
def test = Wrapper(new Person).showType
+8
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

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Person
2+
3+
def test = Wrapper(new Person).nothing
+8
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

+3
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)