-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Macro-based automatic derivation results differ based on how you construct a typeclass instance #16835
Comments
From a quick look into this issue I found that The tree of the implicit search is {
final class $anon() extends Object(), Show[usage.Person2] {
def show(valuea: usage.Person2): String = ...
}
new $anon():Show[usage.Person2]
}:Show[usage.Person2] I would have expected this to succeed the implicit search. Or at least not fail with that error. |
The nested implicit search is reporting an error
This error becomes an impictit search failure. There are two distinct problems:
|
Consider that `val macro` expansion in the context can come from an outer macro that is being expanded (i.e. this is a nested macro). Nested macro expansion can occur when a macro summons an implicit macro. Fixes partially scala#16835
Consider that `val macro` expansion in the context can come from an outer macro that is being expanded (i.e. this is a nested macro). Nested macro expansion can occur when a macro summons an implicit macro. Fixes partially scala#16835
Minimizationimport scala.quoted.*
class Bar
inline def foo: Unit = ${ fooExpr }
def fooExpr(using Quotes): Expr[Unit] =
import quotes.reflect.*
Implicits.search(TypeRepr.of[Bar]) match
case res: ImplicitSearchSuccess => '{}
case failure: ImplicitSearchFailure =>
report.errorAndAbort(s"ImplicitSearchFailure: ${failure.explanation}")
inline given bar: Bar = ${ barExpr }
def barExpr(using Quotes): Expr[Bar] =
import quotes.reflect.*
report.error(s"my error")
'{ new Bar } def test: Unit = foo
|
Fixes partially scala#16835
Thank you very much for a very quick response on this, it's been driving me crazy for some time now but I gaslighted myself into thinking this is correct behavior 😄 |
Fixes partially scala#16835
Consider that `val macro` expansion in the context can come from an outer macro that is being expanded (i.e. this is a nested macro). Nested macro expansion can occur when a macro summons an implicit macro. Fixes partially scala#16835
@arainko this one was a tricky one. It also confused me a lot. The combination of the two errors just made it hard to understand where things went wrong. |
Consider that `val macro` expansion in the context can come from an outer macro that is being expanded (i.e. this is a nested macro). Nested macro expansion can occur when a macro summons an implicit macro. Fixes partially scala#16835
Consider that `val macro` expansion in the context can come from an outer macro that is being expanded (i.e. this is a nested macro). Nested macro expansion can occur when a macro summons an implicit macro. Fixes partially #16835
Compiler version
3.2.1, 3.2.2, 3.3.0-RC2, 3.3.1-RC1-bin-20230204-a356581-NIGHTLY
Minimized code
Output
Expectation
These two versions of automatic derivation should be equivalent or a less cryptic error message
Workarounds
If we alter the definition of
Derivation.lookupShowFor
to include a splice ofsummonInline[Show[tpe]]
instead of aborting, the derivation will succeed in all of the cases:But that severely limits what you can do with an AST like that moving forward (you can't really inspect the trees that
get summoned, from my testing only after the whole tree is spliced
summonInlines
get replaced with actual trees that can be inspected) plus I'd kind of expect thatImplicits.search
will behave just likesummonInline
The text was updated successfully, but these errors were encountered: