-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Manual cast required to preserve dependent types #12345
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
This seems like an instance of the perennial problem that classes lose the precise singleton type of their parameters. There are already a bunch of issues opened about it, e.g., #3964. The workaround is to use a type parameter. |
Placing a In the example, it looks like we are trying to define an extension method the Scala 2 way. Placing the implicit in an object to then refer to it. Now that we support contextual parameters before other parameters we do not need to do this workaround and can define the method directly. See https://docs.scala-lang.org/scala3/guides/macros/reflection.html#macro-api-design. extension (q: Quotes)
def lazyFlags = q.reflect.Flags.Lazy
def test(using Quotes) =
quotes.lazyFlags or object C:
def lazyFlags(using Quotes) = quotes.reflect.Flags.Lazy
def test(using Quotes) =
C.lazyFlags Also try to avoid naming |
@nicolasstucki Not that simple. In my (un-minimised) class I'm statefully storing bits of TASTY. In this case I have to store (and expose) the class C(using val q: Quotes)(flags: q.reflect.Flags) {
import q.reflect.*
var stmts = Vector.empty[Statement]
} |
Indeed, those are a bit more complex. One way I simplified that in the past, which was a bit more verbose was to use type parameters. class C[Flags, Statement](flags: Flags) {
var stmts = Vector.empty[Statement]
}
def app(using Quotes) =
import quotes.reflect.*
new C[Flags, Statement](flags) |
I wonder if something like this would work class C[Q <: Quotes & Singleton](using val q: Q)(flags: q.reflect.Flags) {
import q.reflect.*
var stmts = Vector.empty[Statement]
} Then at call site I used this pattern in the past but I had to add explicitly the |
Compiler version
3.0.0-RC3
Minimized code
Output
Expectation
It should compile.
The text was updated successfully, but these errors were encountered: