-
Notifications
You must be signed in to change notification settings - Fork 21
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
Quill idiom for inferred implicit type with whitebox macro under -Xsource:3
#12798
Comments
The change in question is scala/scala#10083. /cc @som-snytt Can you give an example of what you can't do now? |
Can the macro emit |
This is pre-second-coffee, but you can always write |
@som-snytt any advice we have for macro authors would be good to add to the PR description |
I added a line to the PR without thinking about it, but please add a use case here if necessary. |
The case for me is defining quill's implicit val personMeta = materializedQueryMeta[Person] Quill will use the concrete type info later. If specify type to |
-Xsource:3
-Xsource:3
@jilen Does that mean |
@som-snytt Confirmed adding |
My bad, just find //> using lib org.scala-lang:scala-reflect:2.13.11
//> using scala "2.13.11"
//> using options -Xsource:3
import scala.reflect.macros.whitebox.Context
import scala.language.experimental.macros
class FooMacroImpl(val c: Context) {
import c.universe._
def fooImpl: Tree = {
val c = Constant("foo")
q"${c}"
}
}
object Foo {
def foo: String = macro FooMacroImpl.fooImpl
}
Then
|
@jilen what behavior did you expect, there? |
implicit val foo: Any = Foo.foo I thought the type of |
I'll take a look today. I don't want anything to spoil Seth's Scala Days. Because really, how many Scala Days do have in this life? Every Scala Day is precious. |
Ah, I had misunderstood Som's suggestion, but I understand better now. I'm surprised to learn that that would be expected behavior. when I write @som-snytt you're sure that's expected...? I guess in Scala 3 this issue can't arise because there aren't whitebox macros...? Perhaps one possible resolution here would be to say that it's expected for perhaps @guizmaii could enlighten us on how people using Scala 3 with Quill would be expected to write this code? |
@SethTisue Yes, it's fundamental to whiteboxness and also works that way in Scala 3 via Oh wait, sorry lack of sleep, the implicit is in the wrong place.
lets the type of myimplicit expansion get refined. I'll take a look at how the behavior is relied upon in quill. |
Okay, that makes more sense. But it doesn't seem to help OP. Their desire to have an
I'd like to see a spelled-out example of that; in Scala 3, can I have a |
@som-snytt One thing I don't know here is whether the |
They call it |
-Xsource:3
-Xsource:3
It's written but it's also transparent: https://dotty.epfl.ch/docs/reference/contextual/givens.html#given-macros-1 |
We cannot update to 2.13.11 because of this issue and the fact we cannot add explicit types for Quill. We use |
Not sure if this is clear from the discussion, sorry if I'm just adding noise; the static type of an implicit whitebox macro def defines what type can be summoned: import scala.reflect.macros.whitebox.Context
import scala.language.experimental.macros
class A
class B extends A
class FooMacroImpl(val c: Context) {
import c.universe._
def fooImpl: Tree = {
q"new B()"
}
}
object Foo {
implicit def foo: A = macro FooMacroImpl.fooImpl
}
|
A good approach to migration errors under |
I'll pursue that approach: instead of knobs to enable migration behaviors, Note to self: one way to simplify |
Bottom line what do I do with scala 2.13.12? |
Top line, the idiom of the title is Sample potential dogfooding at https://github.com/scala/scala/pull/10551/files#diff-5634c415cd8c8504fdb973a3ed092300b43c4b8fc1e184f7249eb29a55511f91R417
The wconf is |
The scala
2.13.11
version requires explicit type of implicit definition.Then it become impossible to use
whitebox macro
to return the narrowed type.The text was updated successfully, but these errors were encountered: