-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Scala 2 regression: F-bounds + wildcard #13133
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
Not going to fix all the f-bounds issues sorry :). |
Umm ok.... Why? |
Sorry if it wasn't clear I was reacting to:
To explain why I un-assigned myself. But maybe someone else will be brave enough to try to fix this! |
I think this needs further minimization. F-bounds are a pain, and wildcards are a pain, together they are a royal pain. No idea whether this is supposed to compile or not. Scala 2.12/2.13 can't provide a yardstick here since it's approach is sufficiently different. In other conversations I recommend to eliminate F-bounds entirely and use intersections instead. I think this is the best way forward, and wish we could retire F-bounds from Scala for good. |
Removing F-bounds will make interop with some libraries a lot harder, which is not something I like the idea of. |
@smarter Oh, thanks for clarifying! I was so confused and none of the explanations I could come up with in my head made any sense to me haha. @odersky Yeah F-bounds aren't fun and I don't like to use them very often. The only time I reach for them is have a hierarchy of types and I want to have a method in the super type that allows users to change a type-parameter without losing the subtype identity. Did I explain that correctly? So like if you wanted to have
It's currently minimised to two lines. I could add a semicolon to make it one line if you like hehe. Jokes aside, the snippet looks big only because I've added a bunch of variants. This is probably the best minimisation: trait DomZipper[X, A, Self[B] <: DomZipper[X, B, Self]]
def apply[Fast[a] <: DomZipper[_, a, Fast]] = () // error |
@odersky I just read through the other conversation you linked where you describe how F-bounds can be replaced with intersections. Very cool idea, I tried it out with Scala 2 and it works fine! The pet example for Scala 2: object OkCool {
trait Pet[A] { this: A =>
def name: String
def renamed(newName: String): A with Pet[A]
}
case class Fish(name: String, age: Int) extends Pet[Fish] {
def renamed(newName: String) = copy(name = newName)
}
def esquire[A](a: Pet[A]): Pet[A] = a.renamed(a.name + ", Esq.")
val a = Fish("Jimmy", 2)
val b = a.renamed("Bob")
val c = esquire(b)
} And I tried with a type parameter on the super type: object Poly {
trait Pet[F, Self[_]] { this: Self[F] =>
def food: F
def withFood[G](g: G): Pet[G, Self] with Self[G]
}
case class Fish[F](food: F) extends Pet[F, Fish] {
def withFood[G](g: G): Fish[G] = Fish(g)
def fishFood = food
}
def eatStrings[F, S[_]](p: Pet[F, S]): Pet[String, S] with S[String] =
p.withFood(123).withFood("")
val f = Fish(1)
val g = eatStrings(f)
g.fishFood: String
} Very cool 👍 |
Ah, that's reassuring! I just glanced at the code but was not aware that it exercised multiple independent failures. I'll take a look then but it will have to wait a bit.
Yes, I agree. It's one of the things we inherited from Scala that otherwise we would be better without. Here's a shortlist of awkward Java features we still have to support.
That's what I can think of right now - there are probably others as well. |
It's a missing capture conversion. The error message is
Essentially it needs to argue that for each version of |
Compiler version
Minimized code
Output
Expectation
Compiles with Scala 2.12 and 2.13.
The text was updated successfully, but these errors were encountered: