Skip to content
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

Runtime multi-staging compilation crashes on case class symbols in traits #20370

Open
jchyb opened this issue May 9, 2024 · 0 comments
Open
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:bug

Comments

@jchyb
Copy link
Contributor

jchyb commented May 9, 2024

Compiler version

3.4.1, main

Minimized code

//> using dep "org.scala-lang::scala3-staging:3.4.1"
//> using scala 3.4.1

trait TraitWithCaseClass {
  case class FromTraitRROption(id: Int)
}
object HasTrait extends TraitWithCaseClass {}

object Test  {
  @main def main() =
    import scala.quoted._
    given staging.Compiler = staging.Compiler.make(this.getClass.getClassLoader)

    staging.withQuotes {
      import quotes.reflect._
      val cls = classOf[HasTrait.FromTraitRROption]
      println(Symbol.classSymbol(cls.getName()))
      println(Symbol.classSymbol(cls.getName()).methodMembers)
    }
}

When using scalac directly, -with-compiler must be used.

Output

class TraitWithCaseClass$FromTraitRROption
Exception in thread "main" scala.MatchError: NoType (of class dotty.tools.dotc.core.Types$NoType$)
        at dotty.tools.dotc.core.Types$ThisType.underlying(Types.scala:3100)
        at dotty.tools.dotc.core.Types$TypeProxy.superType(Types.scala:2095)
        at dotty.tools.dotc.core.Types$Type.memberNames(Types.scala:971)
        at dotty.tools.dotc.core.Types$Type.memberDenots(Types.scala:982)
        at dotty.tools.dotc.core.Types$Type.allMembers(Types.scala:1077)
        at scala.quoted.runtime.impl.QuotesImpl$reflect$SymbolMethods$.methodMembers(QuotesImpl.scala:2735)
        at scala.quoted.runtime.impl.QuotesImpl$reflect$SymbolMethods$.methodMembers(QuotesImpl.scala:2734)
        at Test$.main$$anonfun$1(m.scala:18)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.quoted.staging.package$.dummyRun$1(staging.scala:39)
        at scala.quoted.staging.package$.withQuotes$$anonfun$1(staging.scala:42)
        at scala.quoted.staging.QuoteCompiler$QuotedFrontend.runOn$$anonfun$1(QuoteCompiler.scala:85)
        at scala.collection.immutable.List.flatMap(List.scala:293)
        at scala.quoted.staging.QuoteCompiler$QuotedFrontend.runOn(QuoteCompiler.scala:101)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:315)
        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:337)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:350)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:360)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:360)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:267)
        at scala.quoted.staging.QuoteCompiler$ExprRun.compileExpr(QuoteCompiler.scala:121)
        at scala.quoted.staging.QuoteDriver.run(QuoteDriver.scala:43)
        at scala.quoted.staging.Compiler$$anon$1.run(Compiler.scala:50)
        at scala.quoted.staging.package$.withQuotes(staging.scala:42)
        at Test$.main(m.scala:19)
        at main.main(m.scala:10)

Expectation

Lack of crash and the methodMembers method should return a list of methods, like we obtain when using a macro instead of the staging compiler (in a macro this code works correctly).

@jchyb jchyb added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label area:metaprogramming:reflection Issues related to the quotes reflection API labels May 9, 2024
@Gedochao Gedochao removed the stat:needs triage Every issue needs to have an "area" and "itype" label label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:bug
Projects
None yet
Development

No branches or pull requests

2 participants