Closed scabug closed 8 years ago
Imported From: https://issues.scala-lang.org/browse/SI-2182?orig=1 Reporter: yves See #884
@paulp said: This is basically a duplicate of #884 - I've added a pointer from there to here for completeness.
@paulp said: Interestingly this was not really a duplicate of #884. Instead it was something which worked all along. Your real issue was a lack of variance in FinalResult and BaseResult. Yes, I'm aware I closed this 15 months ago and am talking to myself.
Naftoli Gugenheim (naftoligug) said (edited by @paulp on Aug 28, 2016 5:18:01 PM UTC):
I'm confused -- is this really a duplicate of SI-884?
"this was not really a duplicate of SI-884"
If not, what should its status be?
"Not a Bug"
Naftoli Gugenheim (naftoligug) said: @extempore thanks for responding. Next time could you add a comment instead of editing mine? :D I've hit this issue myself. Would you perhaps be so kind as to expand the fix? "Your real issue was a lack of variance in FinalResult and BaseResult" -- do you mean if they were covariant this would work? What does variance have to do with the issue, I don't see any subtype or supertype of X anywhere.
Naftoli Gugenheim (naftoligug) said: trying to change resolution
Naftoli Gugenheim (naftoligug) said: I changed the resolution, I hope that's okay
@paulp said: If it's not obvious, I didn't intend to edit yours. I've only had 8-10 years to master JIRA's intuitive interface, I can't imagine how I could still be making that mistake. Oh wait, yes I can.
@paulp said (edited on Aug 28, 2016 7:08:19 PM UTC): FinalResult[X] is invariant in X. Error extends FinalResult[Nothing]. That means you can't return Error for FinalResult[U] unless U=Nothing.
Naftoli Gugenheim (naftoligug) said (edited on Aug 28, 2016 10:56:26 PM UTC): @Paul Phillips it was obvious, don't worry. :)
(speaking of JIRA UX, I'm trying to figure out the right way to "mention" someone...)
As for the explanation, I see what you mean now. I was too focused on the next line, case r:Result[U] => Success(r.result)
.
Indeed, this does compile:
case class C[A](a: A, modify: A => A)
def test[A](c: C[A]): C[A] = c match { case C(x, f) => C(f(x), f) }
The following code is problematic:
It compiles, but with a warning about type erasure at line
case r:Result[U] => Success(r.result)
However, there doesn't seem to be any way to get rid properly of that warning except by writting
case r:Result[_] => Success(r.result.asInstanceOf[U])
which is long to write and involves an unrequired cast even though we are ensured that r.result cannot be anything but type U.