-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Typing error when inline used together with summons and implicits in imported class #16156
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
Also, is it necessary to do class Repo[T]:
val ctx = new Context
import ctx._ // move to here
inline def summonEncoder = {
summonMyEncoder[T]
}
object Use:
val repo = new Repo[String]
val v = repo.summonEncoder
// [error] -- Error: /home/git/encoder-typing-reproduction/src/main/scala/org/deusaquilus/Use.scala:12:15
// [error] 12 | val v = repo.summonEncoder
// [error] | ^^^^^^^^^^^^^^^^^^
// [error] | can't do it When I do this, no encoder is found and the |
One other thing, when I move the context variable to be passed in via a parameter it also throws an error. class Repo[T]:
inline def summonEncoder(ctx: Context) = { // Pass it in as a parameter
import ctx._ // ... then import it!
summonMyEncoder[T]
}
object Use:
val repo = new Repo[String]
val v = repo.summonEncoder(new Context) Then the following error happens:
|
Imports are supposed to be resolved already, so they need not and should not be copied into inlined code. Fixes scala#16156, unfortuntely in the sense that it will not work.
When inlining the {
import Repo_this.ctx.*
Repo_this.ctx.summonMyEncoder[String]
} But when we expand {
import Repo_this.ctx.*
Repo.this.ctx.encoderInstance.encode
} It looks to me that the implicit search is made in the context of class
|
I noted the same problem happens when the inline methods are |
Compiler version
Error happens in 3.2.0 as well as latest nightly
3.2.2-RC1-bin-20221006-a6a3385-NIGHTLY
.Minimized code
Let's create a context object that has an encoder instance:
Then let's make the macro
SummonEncoder.impl
summon that instance:Then let's create a 'Repo' object that internally uses the context to summon an encoder for a particular type,
...and then use that summoning function.
Output
Long
exception while typing Repo.this...
error happens:Expectation
It should work and summon the encoder property.
Github Example:
You can find an example of the codebase here:
https://github.com/deusaquilus/encoder-typing-reproduction
The exact same problem happens if you change the encoder to a
given
and change the import toimport ctx.{given, _}
.Why this is Important
I would really like to use Scala 3 inline to be able to create DAO repository patterns. That would look something like this:
Only I can't do this because the above error will happen in my encoders and decoders.
The text was updated successfully, but these errors were encountered: