Skip to content

Commit 6d7b79c

Browse files
committed
Avoid Predef.getClass
In top level definitions we used to get `DottyPredef.getClass` when we did `getClass`. Now we get `Predef.getClass` which get us a class that was loaded with the wrong classloader.
1 parent 671f9e4 commit 6d7b79c

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

tests/run-staging/i7897.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import scala.quoted._, staging._
22

3-
given Toolbox = Toolbox.make(getClass.getClassLoader)
3+
object Test:
4+
given Toolbox = Toolbox.make(getClass.getClassLoader)
45

5-
val f: Array[Int] => Int = run {
6-
val stagedSum: Expr[Array[Int] => Int] = '{ (arr: Array[Int]) => 6 }
7-
println(stagedSum.show)
8-
stagedSum
9-
}
6+
val f: Array[Int] => Int = run {
7+
val stagedSum: Expr[Array[Int] => Int] = '{ (arr: Array[Int]) => 6 }
8+
println(stagedSum.show)
9+
stagedSum
10+
}
1011

11-
@main
12-
def Test = {
13-
f.apply(Array(1, 2, 3)) // Returns 6
14-
}
12+
def main(args: Array[String]) = {
13+
f.apply(Array(1, 2, 3)) // Returns 6
14+
}

tests/run-staging/i8178.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ def foo(n: Int, t: Expr[Int])(using Quotes): Expr[Int] =
55
if (n == 0) t
66
else '{ val a = ${Expr(n)}; ${foo(n - 1, 'a)} + $t }
77

8-
@main def Test = {
9-
// make available the necessary toolbox for runtime code generation
10-
given Toolbox = Toolbox.make(getClass.getClassLoader)
8+
object Test:
9+
def main(args: Array[String]) = {
10+
// make available the necessary toolbox for runtime code generation
11+
given Toolbox = Toolbox.make(getClass.getClassLoader)
1112

12-
val f: Int = run { foo(2, Expr(5)) }
13+
val f: Int = run { foo(2, Expr(5)) }
1314

14-
println(f)
15-
}
15+
println(f)
16+
}

0 commit comments

Comments
 (0)