Open scabug opened 8 years ago
Imported From: https://issues.scala-lang.org/browse/SI-9837?orig=1 Reporter: Cary Robbins (carymrobbins) See #6130
@SethTisue said:
Note that the indirection through the type alias Door.K
is not a factor here; the error message is the same if you take that out and just write val key: Key with h.K
.
I haven't studied both tickets closely, but #6130 looks loosely related (but there is no extractor here, so this one seems more fundamental).
@som-snytt said: Why is the error invalid? SilverKey does not conform to some arbitrary door.key, where door.h.Key might be my SpecialSkeletonKey.
The conformance test says, We'll match if SilverKey.equals(a SpecialSkeletonKey), so SilverKey must be competent to make that test.
I think the error is for objects what "constructor cannot be instantiated to expected type" is for case classes?
It's not obvious to me that the upper bound on K means we intend to match on any old Key.
Dotty accepts this code.
@som-snytt it seems to me that the compiler doesn't have to prove that it can match, it must accept the code unless it can prove it can't match
The compiler rejects code which should be perfectly valid. Using type ascription to upcast the value is a workaround for this.