What would cause ClassNotFound in a Scala 3 macro?

31 Views Asked by At

Doing reflection in a macro. Sometimes, only for a few classes (seems to happen for a select few Java classes in a mixed project) Class.forName() doesn't work when testing.

For example this works:

RType.of[JavaParam[Boolean]] // macro call - compile-time

And this fails--for a few certain classes (a Java class, in this case). All Scala classes and most other Java classes work this way, no problem.

RType.of("my.samples.JavaParam") // calls Class.forName

(This second call should reflect on the generic JavaParam class with no types given for the generic parameters.). The success of the first call should prove JavaParam is visible on the classpath, right? The only difference is the top one is executing at runtime (macro expansion) and the bottom is 100% runtime. Just to test a theory, I tried this in my test code (runtime), and it succeeded, so yes--it should be visible on the classpath:

val foo = new JavaParam()

Why do I get ClassNotFoundExceptions for this? And what I can I do fix it?

0

There are 0 best solutions below