-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not expose ClassInfo in memberType in reflect API
- Loading branch information
Showing
9 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
-- Error: tests/neg-macros/i15159/Test_2.scala:5:16 -------------------------------------------------------------------- | ||
5 | TestMacro.test[A] // error | ||
| ^^^^^^^^^^^^^^^^^ | ||
| Exception occurred while executing macro expansion. | ||
| java.lang.AssertionError: class X is not a member of A | ||
| at TestMacro$.testImpl$$anonfun$1(Macro_1.scala:8) | ||
| at scala.collection.immutable.List.map(List.scala:247) | ||
| at TestMacro$.testImpl(Macro_1.scala:7) | ||
| | ||
|--------------------------------------------------------------------------------------------------------------------- | ||
|Inline stack trace | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
|This location contains code that was inlined from Macro_1.scala:3 | ||
3 | inline def test[T]: Unit = ${ testImpl[T] } | ||
| ^^^^^^^^^^^^^^^^ | ||
--------------------------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import scala.quoted.* | ||
object TestMacro: | ||
inline def test[T]: Unit = ${ testImpl[T] } | ||
def testImpl[T: Type](using Quotes): Expr[Unit] = | ||
import quotes.reflect.* | ||
val tpe = TypeRepr.of[T] | ||
tpe.typeSymbol.children.map { childSymbol => | ||
tpe.memberType(childSymbol) // not a member of tpe | ||
} | ||
'{ () } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sealed trait A | ||
case class X(i: Int) extends A | ||
|
||
object Test extends App { | ||
TestMacro.test[A] // error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import scala.quoted._ | ||
object Macro: | ||
inline def apply[A]: Unit = ${impl[A]} | ||
|
||
private def impl[A: Type](using Quotes): Expr[String] = | ||
import quotes.reflect._ | ||
val t = TypeRepr.of[A] | ||
Expr.ofList(t.baseClasses.drop(1).filter(_.flags.is(Flags.Trait)).map { baseSymbol => | ||
t.memberType(baseSymbol).asType match { case '[t] => 42} | ||
Expr("") | ||
}) | ||
Expr("") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@main def Test = Macro[Option[String]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TypeRef(AppliedType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class <root>)),module class <empty>)),Foo),List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),Int))),class Nested) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import scala.quoted._ | ||
|
||
inline def test(): String = ${testImpl} | ||
def testImpl(using Quotes) = { | ||
import quotes.reflect._ | ||
val fooSymbol = TypeRepr.of[Foo[Int]].typeSymbol | ||
val nestedSymbol = fooSymbol.typeMember("Nested") | ||
|
||
Expr(TypeRepr.of[Foo[Int]].memberType(nestedSymbol).toString) | ||
} | ||
|
||
|
||
trait Foo[X]: | ||
sealed abstract class Nested extends Foo[Int] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@main def Test = | ||
println(test()) |