File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
sbt-dotty/sbt-test/sbt-dotty/quoted-example-project/src/main/scala/hello Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -16,9 +16,16 @@ object Toolbox {
16
16
implicit def make (implicit settings : Settings ): Toolbox = Toolbox .make
17
17
}
18
18
19
- def make2 (obj : Any )(implicit settings : Settings ): Toolbox = {
19
+ @ forceInline def make4 (implicit settings : Settings ): Toolbox = {
20
+ // TODO find the name of the class that needs to be loaded. Maybe from a stack trace.
21
+
22
+ // We force inline to make forName use the classloader of the class at callsite
23
+ val cl = Class .forName(" hello.Main" ).getClassLoader
24
+ make2(cl)
25
+ }
26
+
27
+ def make2 (cl : ClassLoader )(implicit settings : Settings ): Toolbox = {
20
28
try {
21
- val cl = obj.getClass().getClassLoader()
22
29
val toolboxImplCls = cl.loadClass(" dotty.tools.dotc.quoted.ToolboxImpl" )
23
30
val makeMeth = toolboxImplCls.getMethod(" make2" , classOf [Settings ], classOf [ClassLoader ])
24
31
makeMeth.invoke(null , settings, cl).asInstanceOf [Toolbox ]
Original file line number Diff line number Diff line change @@ -5,7 +5,10 @@ import scala.quoted._
5
5
6
6
object Main {
7
7
8
- implicit val toolbox : scala.quoted.Toolbox = scala.quoted.Toolbox .make2(this )
8
+ // val cl = Class.forName("hello.Main").getClassLoader
9
+ // implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make2(cl)
10
+
11
+ implicit val toolbox : scala.quoted.Toolbox = scala.quoted.Toolbox .make4
9
12
10
13
def main (args : Array [String ]): Unit = {
11
14
val square = stagedPower(2 )
You can’t perform that action at this time.
0 commit comments