-
Notifications
You must be signed in to change notification settings - Fork 58
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
Transmogrification fails if common field implements LabelledGeneric
#143
Comments
Ah, I've worked out why this is failing, the compiler has hit the decision of whether to use the Not sure what can be done here (especially if one wanted to move between these two |
Yep, this issue was known since before the feature was added, and to be honest is something I regard as a crippling limitation. I really don't know what can be done about it in the confines of rust's trait system. |
Indeed, this was known and is noted in the Transmogrification section as well. It's a fairly annoying limitation, true, but I decided to add it because (1) it's still got some use and (2) when specialisation is done we can hit the ground running :) |
Ah, yes, I missed that warning text. Two follow on questions:
|
I'll have to admit that I don't have an up-to-date view of what specialisation will bring in Rust, so you could well be right :D. In Scala, something like this works: @ {
trait Foo[A] {
def go(o: A): Unit
}
object Foo {
implicit val intFoo: Foo[Int] = new Foo[Int] {
def go(o: Int): Unit = println(s"int foo [$o]")
}
implicit def allFoo[A]: Foo[A] = new Foo[A] {
def go(o: A): Unit = println(s"all foo [$o]")
}
}
}
defined trait Foo
defined object Foo
@ def fooIt[A: Foo](o: A) = implicitly[Foo[A]].go(o)
defined function fooIt
@ fooIt(3)
int foo [3]
@ fooIt("hello")
all foo [hello]
Yeah, I'm pretty sure that it is possible to do something like that to steer the inference (at the very least, I did this during at least one of the implementations); but yeah, as you said, without something like a procedural macro it would be hard to do right. Definitely worth exploring though ! |
I lack confidence that specialization will help. In the current form of the trait, specialization is ineffectual. This means
And... well... I dunno! I really don't understand how specialization works or how much of it is even implemented, to be honest. I gave it a try, sprinking |
116: Revert "Add frunk support for swagger::Nullable" r=richardwhiuk a=richardwhiuk This reverts commit 92f6f85. This reverts #114 which caused problems due to lloydmeta/frunk#143 Co-authored-by: Richard Whitehouse <[email protected]>
116: Revert "Add frunk support for swagger::Nullable" r=richardwhiuk a=richardwhiuk This reverts commit 92f6f85. This reverts #114 which caused problems due to lloydmeta/frunk#143 Co-authored-by: Richard Whitehouse <[email protected]>
116: Revert "Add frunk support for swagger::Nullable" r=richardwhiuk a=richardwhiuk This reverts commit 92f6f85. This reverts #114 which caused problems due to lloydmeta/frunk#143 Co-authored-by: Richard Whitehouse <[email protected]> Signed-off-by: Richard Whitehouse <[email protected]>
A basic (working) example of transmogrification might look like:
This compiles and works just fine but, if you change the definition of
Foo2
to be[1]:Then the compile fails with the error:
Strangely, if
Bar
does not implementLabelledGeneric
then the code compiles and works as expected. (Have you accidentally tricked the compiler into implementing specialization on stable?!)This makes it hard to mix types in structs, since no two
LabelledGeneric
fields can ever be common between twoLabelledGeneric
structs.[1](Note that this means that
Foo
andFoo2
are identical, though this need not be the case in general, as other fields may be present and differ up to transmogrifiability without affecting the result)The text was updated successfully, but these errors were encountered: