Skip to content

Synthetic top-level <init> member causes Types.member to crash #16666

Closed
@szymon-rd

Description

@szymon-rd

Causes #16650, can cause other problems in the future. For now, #16550 is fixed with a workaround.

Compiler version

3.3.0-RC1-bin-20230109-f56089b-NIGHTLY

Minimized code

LinearMap.scala file:

//> using scala "3.3.0-RC1-bin-20230109-f56089b-NIGHTLY"
package repro

val z = 3

LinearSet.scala file:

//> using scala "3.3.0-RC1-bin-20230109-f56089b-NIGHTLY"
package repro

val x = 2

Compile two above files in separate run, and put them in a jar file. Breaks only if the classpath in the snippet below is a jar - does not work with a directory of class and tasty files.

scala-cli package --library -o out.jar LinearMap.scala LinearSet.scala -f

Then, compile a Macro and a file calling this macro:

Macro.scala file:

import scala.quoted.*

inline def foo = ${ fooImpl }

def fooImpl(using Quotes) =
    import quotes.reflect.*

    val x = Symbol.requiredPackage("repro")
    val y = Select.unique(Ref(x), "<init>")

    println(y)

    '{}

Main.scala file:

//> using scala "3.3.0-RC1-bin-20230109-f56089b-NIGHTLY"

val x = foo

Run these files with dependency on the jar:

scala-cli compile Main.scala Macro.scala -cp out.jar --server=false

Output

-- Error: /**/repro/Main.scala:3:8 
3 |val x = foo
  |        ^^^
  |Exception occurred while executing macro expansion.
  |dotty.tools.dotc.core.TypeError$$anon$1: Toplevel definition <init> is defined in
  |  /**/repro/out.jar(repro/LinearSet$package.class)
  |and also in
  |  /**/repro/out.jar(repro/LinearMap$package.class)
  |One of these files should be removed from the classpath.
  |
  |-----------------------------------------------------------------------------
  |Inline stack trace
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  |This location contains code that was inlined from Macro.scala:3
3 |inline def foo = ${ fooImpl }
  |                 ^^^^^^^^^^^^
   -----------------------------------------------------------------------------
1 error found
Compilation failed

Expectation

No error

Stack trace at crash

(at #16650 the scenario is very similar - the member function is called in the same scenario )

       at java.base/java.lang.Thread.dumpStack(Thread.java:1380)
        at dotty.tools.dotc.core.SymDenotations$PackageClassDenotation.dropStale$1(SymDenotations.scala:2501)
        at dotty.tools.dotc.core.SymDenotations$PackageClassDenotation.recur$5(SymDenotations.scala:2466)
        at dotty.tools.dotc.core.SymDenotations$PackageClassDenotation.computeMembersNamed(SymDenotations.scala:2523)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamed(SymDenotations.scala:2078)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:2129)
        at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:690)
        at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:873)
        at dotty.tools.dotc.core.Types$Type.memberBasedOnFlags(Types.scala:673)
        at dotty.tools.dotc.core.Types$Type.member(Types.scala:657)
        at scala.quoted.runtime.impl.QuotesImpl$reflect$Select$.unique(QuotesImpl.scala:488)
        at scala.quoted.runtime.impl.QuotesImpl$reflect$Select$.unique(QuotesImpl.scala:487)
        at Macro$package$.fooImpl(Macro.scala:9)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:577)
        at dotty.tools.dotc.quoted.Interpreter.interpretedStaticMethodCall$$anonfun$1(Interpreter.scala:174)
        at dotty.tools.dotc.quoted.Interpreter.stopIfRuntimeException(Interpreter.scala:231)
        at dotty.tools.dotc.quoted.Interpreter.interpretedStaticMethodCall(Interpreter.scala:174)
        at dotty.tools.dotc.quoted.Interpreter.interpretTree(Interpreter.scala:76)
        at dotty.tools.dotc.transform.Splicer$SpliceInterpreter.interpretTree(Splicer.scala:247)
        at dotty.tools.dotc.quoted.Interpreter.interpretTree$$anonfun$2(Interpreter.scala:95)
        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:1041)
        at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedApply(Inliner.scala:818)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2914)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2977)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
        at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:903)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3044)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3048)
        at dotty.tools.dotc.typer.ReTyper.typedTyped(ReTyper.scala:64)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2919)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2977)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
        at dotty.tools.dotc.inlines.Inliner$InlineTyper.typedUnadapted(Inliner.scala:903)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3044)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3041)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3048)
        at dotty.tools.dotc.inlines.Inliner.inlined(Inliner.scala:671)
        at dotty.tools.dotc.inlines.Inlines$InlineCall.expand(Inlines.scala:444)
        at dotty.tools.dotc.inlines.Inlines$.inlineCall(Inlines.scala:151)
        at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:84)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1473)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:73)
        at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:78)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1225)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1225)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1227)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:64)
        at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:90)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1478)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:73)
        at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:78)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1225)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1225)
        at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1227)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1486)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:73)
        at dotty.tools.dotc.transform.Inlining$InliningTreeMap.transform(Inlining.scala:90)
        at dotty.tools.dotc.transform.Inlining$$anon$2.transform(Inlining.scala:62)
        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:324)
        at scala.collection.immutable.List.map(List.scala:246)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:328)
        at dotty.tools.dotc.transform.Inlining.runOn(Inlining.scala:38)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:244)
        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:1321)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:260)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:268)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:277)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:277)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:201)
        at dotty.tools.dotc.Driver.finish(Driver.scala:56)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:36)
        at dotty.tools.dotc.Driver.process(Driver.scala:195)
        at dotty.tools.dotc.Driver.process(Driver.scala:163)
        at dotty.tools.dotc.Driver.process(Driver.scala:175)
        at dotty.tools.dotc.Driver.main(Driver.scala:205)
        at dotty.tools.dotc.Main.main(Main.scala)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions