Skip to content

ClassNotFoundException when evaluating inline def which calls a macro defined in a super-class #18393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
smarter opened this issue Aug 13, 2023 · 2 comments · Fixed by #18396
Closed
Assignees
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug

Comments

@smarter
Copy link
Member

smarter commented Aug 13, 2023

Compiler version

3.3.0

Minimized code

Macro_1.scala:

package defn

import scala.quoted.*

abstract class Macro {
  def impl()(using Quotes): Expr[Int] = '{1}
}

Inline_2.scala:

package user

import defn.Macro

object Inline extends Macro {
  inline def callMacro(): Int =
    ${ this.impl() }
}

Test_2.scala:

package user

object Test {
  Inline.callMacro()
}
$ mkdir out1 out2
$ scalac Macro_1.scala -d out1
$ scalac -classpath out1 -d out2 Inline_2.scala Test_2.scala
-- Error: Test_2.scala:4:18 ----------------------------------------------------
4 |  Inline.callMacro()
  |  ^^^^^^^^^^^^^^^^^^
  |Failed to evaluate macro.
  |  Caused by class java.lang.ClassNotFoundException: user.Inline$
  |    java.lang.ClassLoader.loadClass(ClassLoader.java:418)
  |    java.lang.ClassLoader.loadClass(ClassLoader.java:351)
  |    dotty.tools.dotc.quoted.Interpreter.loadClass(Interpreter.scala:214)
  |    dotty.tools.dotc.quoted.Interpreter.loadModule(Interpreter.scala:199)
  |    dotty.tools.dotc.quoted.Interpreter.liftedTree1$1(Interpreter.scala:165)
  |    dotty.tools.dotc.quoted.Interpreter.interpretedStaticMethodCall(Interpreter.scala:170)
  |    dotty.tools.dotc.quoted.Interpreter.interpretTree(Interpreter.scala:85)
  |    dotty.tools.dotc.transform.Splicer$SpliceInterpreter.interpretTree(Splicer.scala:247)
  |    dotty.tools.dotc.quoted.Interpreter.interpretTree$$anonfun$2(Interpreter.scala:95)
  |
1 error found

Weirdly enough, if the package where the inline definition is present exists on the classpath, then it works:

$ mkdir out1/user
$ scalac -classpath out1 -d out2 Inline_2.scala Test_2.scala
$

Expectation

Successful compilation.

@smarter smarter added itype:bug area:metaprogramming:quotes Issues related to quotes and splices labels Aug 13, 2023
smarter added a commit to smarter/carac that referenced this issue Aug 13, 2023
@nicolasstucki
Copy link
Contributor

We should suspend the compilation of Test_2.scala. Compiling this with -Xprint-suspension we do not see any suspensions.

@michelou
Copy link
Contributor

Backport candidate to 3.3.1 branch ?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants