Open
Description
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).