on master help sign in
Fix #1143, properly unify rigid type vars that are supers
dae8e04Evan Czaplicki
src/Type/Unify.hs+21−8
@@ -241,10 +241,20 @@ unifyRigid context maybeSuper maybeName otherContent =
241 return ()
241 return ()
242
242
243 Var Flex otherMaybeSuper _ ->
243 Var Flex otherMaybeSuper _ ->
244− if maybeSuper == otherMaybeSuper then
244+ case (maybeSuper, otherMaybeSuper) of
245+ (_, Nothing) ->
245− merge context (Var Rigid maybeSuper maybeName)
246+ merge context (Var Rigid maybeSuper maybeName)
246− else
247+
248+ (Nothing, Just _) ->
249+ mismatch context (Just (badRigid maybeName))
250+
251+ (Just super, Just otherSuper) ->
252+ case combineSupers super otherSuper of
253+ Right newSuper | newSuper == otherSuper ->
254+ merge context otherContent
255+
256+ _ ->
247− mismatch context (Just (badRigid maybeName))
257+ mismatch context (Just (badRigid maybeName))
248
258
249 Var Rigid _ otherMaybeName ->
259 Var Rigid _ otherMaybeName ->
250 mismatch context $ Just $
260 mismatch context $ Just $
@@ -279,10 +289,13 @@ unifySuper context super otherContent =
279 mismatch context (Just (doubleBad (errorSuper super) (Error.Rigid maybeName)))
289 mismatch context (Just (doubleBad (errorSuper super) (Error.Rigid maybeName)))
280
290
281 Var Rigid (Just otherSuper) maybeName ->
291 Var Rigid (Just otherSuper) maybeName ->
282− if super == otherSuper then
292+ case combineSupers super otherSuper of
293+ Right newSuper | newSuper == super ->
283− merge context otherContent
294+ merge context otherContent
284− else
295+
296+ _ ->
297+ mismatch context $ Just $
285− mismatch context (Just (doubleBad (errorSuper super) (Error.Rigid maybeName)))
298+ doubleBad (errorSuper super) (Error.Rigid maybeName)
286
299
287 Var Flex Nothing _ ->
300 Var Flex Nothing _ ->
288 merge context (Var Flex (Just super) Nothing)
301 merge context (Var Flex (Just super) Nothing)