SR-14428 Comparing enum with associated value gives misleading error about unrelated enum
Issue Description:
enumCompassPoint {
caseNorth(Int)
caseSouthcaseEastcaseWest
}
funcisNorth(c : CompassPoint) -> Bool {
returnc == .North// error: binary operator '==' cannot be applied to operands of type 'CompassPoint' and '_' return c == .North// error: cannot infer contextual base in reference to member 'North'
}
funcisSouth(c : CompassPoint) -> Bool {
returnc == .South// error: binary operator '==' cannot be applied to two 'CompassPoint' operands// note: binary operator '==' cannot be synthesized for enums with associated values
}
Notice that the diagnostic is better for the c == .South case. It would be nice if the type-checker could recognize that in the c == .North case, the user was trying to access CompassPoint.North and emit a more useful diagnostic.
The text was updated successfully, but these errors were encountered:
Interested! Thanks for the ping theindigamer (JIRA User) =]
I think this is somewhat related to SR-12908, not exactly sure is a dupe but I think they are similar
Good spot, they are quite similar. There's a slight difference in that, in this case, CompassPoint doesn't have an Equatable conformance, whereas in the latter case, Result does have a conditional conformance but that is not used because TwoValues does not have an Equatable conformance.
I don't know if that makes this one easier to provide a better diagnostic for, compared to SR-12908.
Additional Detail from JIRA
md5: 34e58d22ee98f59e77c57a4b3543f250
is duplicated by:
Issue Description:
Notice that the diagnostic is better for the
c == .South
case. It would be nice if the type-checker could recognize that in thec == .North
case, the user was trying to accessCompassPoint.North
and emit a more useful diagnostic.The text was updated successfully, but these errors were encountered: