-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cannot splice arbitary type in macros #8865
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
The way to make this work is by creating an existential type typeOf[A].seal match
case '[$tpe] =>
'{ (a: $tpe) => ???} Maybe we should revisit the API for sealing types. We should have an API that always provides an existential type for the |
We have logic in the compiler to do this sort of things automatically for wildcard types it's called skolemization, maybe this could be extended to deal with quotes: https://github.com/lampepfl/dotty/blob/5d6d6aa3797d000800d68f027574aeaee47aa3c2/compiler/src/dotty/tools/dotc/typer/Typer.scala#L3211-L3216 |
Maybe it should be something like typeOf[A].sealIn { [U] => '{ (a: U) => ???} } where the type gets a name def sealIn[T](using ctx: Context)(f: [U] => scala.quoted.Type[U] ?=> T): T Those are the same things we probide when we do typeOf[A].seal match
case '[$tpe] =>
'{ (a: $tpe) => ???} The issue is that there is an implementation restriction on polymorphic types with implicits.
@smarter would it be possible to remove this restriction? |
Probably, I don't remember why this restriction is in place currently. But I'm not sure I understand why this would be needed here, if you already have a stable value then it should be possible to use it even if its type contains a wildcard type I think. |
@smarter There was something about raw polymorphic values being unsound or dangerous, so they're restricted to Function* type, I guess excluding context functions wasn't intentional. |
The current way to do it is using quoted patterns (see #8865 (comment)). If we get support for the alternative using polymorphic function type we will be able to implement that outside the standard library. |
Minimized example
Output
Expectation
It should be possible to splice the type. It's also not possible to splice types which are obtained from TASTY reflect.
If we cast to
Type[_ <: Any]
, the above snippet works. Because of this I suspect that the code isn't sound and I should be doing some form of check before splicing.The text was updated successfully, but these errors were encountered: