File tree 2 files changed +29
-1
lines changed
staging/src/scala/quoted/staging
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,19 @@ private class QuoteDriver(appClassloader: ClassLoader) extends Driver:
53
53
val method = clazz.getMethod(" apply" )
54
54
val inst = clazz.getConstructor().newInstance()
55
55
56
- method.invoke(inst).asInstanceOf [T ]
56
+ try method.invoke(inst).asInstanceOf [T ]
57
+ catch case ex : java.lang.reflect.InvocationTargetException =>
58
+ ex.getCause match
59
+ case ex : java.lang.NoClassDefFoundError =>
60
+ throw new Exception (
61
+ s """ `scala.quoted.staging.run` failed to load a class.
62
+ |The classloader used for the `staging.Compiler` instance might not be the correct one.
63
+ |Make sure that this classloader is the one that loaded the missing class.
64
+ |Note that the classloader that loads the standard library might not be the same as
65
+ |the one that loaded the application classes. """ .stripMargin,
66
+ ex)
67
+
68
+ case _ => throw ex
57
69
end match
58
70
59
71
end run
Original file line number Diff line number Diff line change
1
+ import scala .quoted .*
2
+
3
+ given staging .Compiler =
4
+ staging.Compiler .make(getClass.getClassLoader) // warn: Suspicious top-level unqualified call to getClass
5
+
6
+ class A (i : Int )
7
+
8
+ def f (i : Expr [Int ])(using Quotes ): Expr [A ] = { ' { new A ($i) } }
9
+
10
+ @ main def Test = {
11
+ try
12
+ val g : Int => A = staging.run { ' { (i : Int ) => $ { f(' {i}) } } }
13
+ println(g(3 ))
14
+ catch case ex : Exception =>
15
+ assert(ex.getMessage().startsWith(" `scala.quoted.staging.run` failed to load a class." ))
16
+ }
You can’t perform that action at this time.
0 commit comments