Skip to content

Dependency missing from REPL's classpath when referenced in a macro #21229

Closed
@prolativ

Description

@prolativ

Compiler version

Tested to crash with:

  • scala
    • 3.3.3
    • 3.6.0-RC1-bin-20240718-bd84584-NIGHTLY
  • scala-cli: 1.4.1

Minimized code

Pprint.scala:

//> using scala 3.3.3
//> using dep "com.lihaoyi::pprint::0.9.0"

import scala.quoted.*

def foo = pprint(1)

inline def bar = pprint(1)

inline def baz = ${ bazImpl }
def bazImpl(using Quotes) = '{ pprint(1) }

PprintMain.scala:

@main def run() =
  val a = foo
  val b = bar
  val c = baz

Output

Running

scala-cli repl Pprint.scala
scala> baz

results in a crash:

  unhandled exception while running inlining on rs$line$1

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/lampepfl/dotty/issues/new/choose

     while compiling: rs$line$1
        during phase: inlining
                mode: Mode(ImplicitsEnabled,ReadPositions,Interactive)
     library version: version 2.13.12
    compiler version: version 3.3.3
            settings: -Ycook-docs true -Yread-docs true -classpath /Users/mpalka/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.3/scala3-library_3-3.3.3.jar:/Users/mpalka/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.0/pprint_3-0.9.0.jar:/Users/mpalka/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar:/Users/mpalka/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/fansi_3/0.5.0/fansi_3-0.5.0.jar:/Users/mpalka/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/sourcecode_3/0.4.0/sourcecode_3-0.4.0.jar -d <REPL compilation output>

Exception in thread "main" java.lang.NoClassDefFoundError: fansi/Str
        at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
        at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
        at java.base/java.lang.Class.getMethodsRecursive(Class.java:3307)
        at java.base/java.lang.Class.getMethod0(Class.java:3293)
        at java.base/java.lang.Class.getMethod(Class.java:2106)
        at dotty.tools.dotc.quoted.Interpreter.getMethod(Interpreter.scala:219)
        at dotty.tools.dotc.quoted.Interpreter.interpretedStaticMethodCall(Interpreter.scala:171)
        at dotty.tools.dotc.quoted.Interpreter.interpretTree(Interpreter.scala:80)
        at dotty.tools.dotc.transform.Splicer$SpliceInterpreter.interpretTree(Splicer.scala:258)
        at dotty.tools.dotc.quoted.Interpreter.interpretTree$$anonfun$2(Interpreter.scala:99)
        at dotty.tools.dotc.transform.Splicer$.$anonfun$2(Splicer.scala:60)
        at scala.Option.fold(Option.scala:263)
        at dotty.tools.dotc.transform.Splicer$.splice(Splicer.scala:60)
        at dotty.tools.dotc.inlines.Inliner.dotty$tools$dotc$inlines$Inliner$$expandMacro(Inliner.scala:1048)
        at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedSplice(Inliner.scala:839)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3094)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:153)
        at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191)
        at dotty.tools.dotc.typer.ReTyper.typedTyped(ReTyper.scala:65)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3055)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:153)
        at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:915)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191)
        at dotty.tools.dotc.inlines.Inliner.inlined(Inliner.scala:681)
        at dotty.tools.dotc.inlines.Inlines$InlineCall.expand(Inlines.scala:449)
        at dotty.tools.dotc.inlines.Inlines$.inlineCall(Inlines.scala:152)
        at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:95)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1570)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:67)
        at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:89)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1244)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1244)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1246)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:58)
        at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:108)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1575)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:67)
        at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:89)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1244)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1244)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1246)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1586)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:67)
        at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:97)
        at dotty.tools.dotc.transform.Inlining$$anon$2.transform(Inlining.scala:58)
        at dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:18)
        at dotty.tools.dotc.transform.Inlining.run(Inlining.scala:34)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:327)
        at scala.collection.immutable.List.map(List.scala:246)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:331)
        at dotty.tools.dotc.transform.Inlining.runOn(Inlining.scala:38)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:262)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:71)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:279)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:200)
        at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:87)
        at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:307)
        at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:269)
        at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:169)
        at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:172)
        at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:211)
        at dotty.tools.repl.ReplDriver.runBody$$anonfun$1(ReplDriver.scala:185)
        at dotty.tools.runner.ScalaClassLoader$.asContext(ScalaClassLoader.scala:80)
        at dotty.tools.repl.ReplDriver.runBody(ReplDriver.scala:185)
        at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:172)
        at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:134)
        at dotty.tools.repl.Main$.main(Main.scala:7)
        at dotty.tools.repl.Main.main(Main.scala)
Caused by: java.lang.ClassNotFoundException: fansi.Str
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        ... 80 more

Calling foo and bar don't cause such problems. Also

scala-cli run Pprint.scala PprintMain.scala

works without a crash.
Starting the REPL with an explicit dependency

scala-cli repl Pprint.scala --dep "com.lihaoyi::pprint::0.9.0"

doesn't work as a workaround.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions