Skip to content

Commit 811804d

Browse files
committed
Add tests
1 parent ac7c395 commit 811804d

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

library/src/scala/tasty/reflect/CompilerInterface.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ trait CompilerInterface {
157157
/** Get module symbol if module is either defined in current compilation run or present on classpath. */
158158
def Context_requiredModule(self: Context)(path: String): Symbol
159159

160-
/** Get method symbol if method is either defined in current compilation run or present on classpath. */
160+
/** Get method symbol if method is either defined in current compilation run or present on classpath. Throws if the method has an overload. */
161161
def Context_requiredMethod(self: Context)(path: String): Symbol
162162

163163
//

library/src/scala/tasty/reflect/ContextOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ trait ContextOps extends Core {
1919
/** Get module symbol if module is either defined in current compilation run or present on classpath. */
2020
def requiredModule(path: String): Symbol = internal.Context_requiredModule(self)(path)
2121

22-
/** Get method symbol if method is either defined in current compilation run or present on classpath. */
22+
/** Get method symbol if method is either defined in current compilation run or present on classpath. Throws if the method has an overload. */
2323
def requiredMethod(path: String): Symbol = internal.Context_requiredMethod(self)(path)
2424

2525
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
java
2+
java.lang
3+
scala
4+
scala.collection
5+
java.lang.Object
6+
scala.Any
7+
scala.Any
8+
scala.AnyVal
9+
scala.Unit
10+
scala.Null
11+
scala.None
12+
scala.package$.Nil
13+
scala.collection.immutable.List$.empty
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import scala.quoted._
2+
3+
object Macro {
4+
inline def foo: String = ${ fooImpl }
5+
def fooImpl(given qctx: QuoteContext): Expr[String] = {
6+
import qctx.tasty.{given, _}
7+
val list = List(
8+
rootContext.requiredPackage("java"),
9+
rootContext.requiredPackage("java.lang"),
10+
rootContext.requiredPackage("scala"),
11+
rootContext.requiredPackage("scala.collection"),
12+
13+
rootContext.requiredClass("java.lang.Object"),
14+
rootContext.requiredClass("scala.Any"),
15+
rootContext.requiredClass("scala.AnyRef"),
16+
rootContext.requiredClass("scala.AnyVal"),
17+
rootContext.requiredClass("scala.Unit"),
18+
rootContext.requiredClass("scala.Null"),
19+
20+
rootContext.requiredModule("scala.None"),
21+
rootContext.requiredModule("scala.Nil"),
22+
23+
rootContext.requiredMethod("scala.List.empty"),
24+
)
25+
Expr(list.map(_.fullName).mkString("\n"))
26+
}
27+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
object Test {
3+
def main(args: Array[String]): Unit = {
4+
println(Macro.foo)
5+
}
6+
}

0 commit comments

Comments
 (0)