-
Notifications
You must be signed in to change notification settings - Fork 1.1k
ClassInfo can appear as result of memberType
in macros
#13319
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
Comments
It seems to fail on non-Scala interfaces as well: |
That's the same as in the original report. Did you see another one too? |
@dwijnand I was confident I saw it for |
[error] |Exception occurred while executing macro expansion.
[error] |scala.MatchError: ClassInfo(ThisType(TypeRef(NoPrefix,module class io)), trait Serializable, List(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any))) (of class dotty.tools.dotc.core.Types$CachedClassInfo)
[error] | at scala.quoted.runtime.impl.printers.Extractors$ExtractorsPrinter.visitType(Extractors.scala:233)
[error] | at scala.quoted.runtime.impl.printers.Extractors$.showType(Extractors.scala:12)
[error] | at scala.quoted.runtime.impl.QuotesImpl$$anon$17.show(QuotesImpl.scala:2898)
[error] | at scala.quoted.runtime.impl.QuotesImpl$$anon$17.show(QuotesImpl.scala:2897)
[error] | at scala.quoted.runtime.impl.QuotesImpl$reflect$TypeReprMethods$.show(QuotesImpl.scala:1660)
[error] | at scala.quoted.runtime.impl.QuotesImpl$reflect$TypeReprMethods$.show(QuotesImpl.scala:1660)
[error] | at scala.quoted.runtime.impl.printers.SourceCode$SourceCodePrinter.printType(SourceCode.scala:1228)
[error] | at scala.quoted.runtime.impl.printers.SourceCode$.showType(SourceCode.scala:13)
[error] | at scala.quoted.runtime.impl.QuotesImpl$$anon$14.show(QuotesImpl.scala:2886)
[error] | at scala.quoted.runtime.impl.QuotesImpl$$anon$14.show(QuotesImpl.scala:2885)
[error] | at scala.quoted.runtime.impl.QuotesImpl$reflect$TypeReprMethods$.show(QuotesImpl.scala:1660)
[error] | at scala.quoted.runtime.impl.QuotesImpl$reflect$TypeReprMethods$.show(QuotesImpl.scala:1660)
[error] | at Macro$.impl$$anonfun$2(Macro.scala:11)
[error] | at scala.collection.immutable.List.map(List.scala:246)
[error] | at Macro$.impl(Macro.scala:13)
[error] | at Macro$.inline$impl(Macro.scala:5)
|
memberType
in macros
I came across a similar issue with matching on the result of package mcr
import scala.quoted.*
trait CaseClass[Companion <: AnyRef]:
type CC <: Product
object CaseClass:
transparent inline given mkCaseClass[Comp <: AnyRef]: CaseClass[Comp] = ${
macroImpl[Comp]
}
def macroImpl[Comp <: AnyRef](using Quotes, Type[Comp]): Expr[CaseClass[Comp]] =
import quotes.reflect.*
val compObjTpe = TypeRepr.of[Comp]
val clsSym = compObjTpe.typeSymbol.companionClass
if !clsSym.paramSymss.forall(_.headOption.forall(_.isTerm)) then
report.throwError("Case class with type parameters are not supported")
val compPrefix = compObjTpe match
case TermRef(pre, _) => pre
case _ => report.throwError("Case class companion must be a term ref")
val clsTpe = compPrefix.memberType(clsSym) // memberType returns ClassInfo here
report.info(s"Case class type: ${clsTpe}")
// clsTpe.asType match // uncomment causes match error when calling macro
// case '[t] =>
'{
new CaseClass[Comp]:
type CC = Nothing
}
end CaseClass |
Compiler version
3.0.1
Minimized code
Output (click arrow to expand)
The text was updated successfully, but these errors were encountered: