@@ -622,32 +622,34 @@ detectDuplicates tag names =
623checkTypeVarsInUnion :: A.Commented (D.Union Type.Raw) -> Result wrn ()
623checkTypeVarsInUnion :: A.Commented (D.Union Type.Raw) -> Result wrn ()
624checkTypeVarsInUnion (A.A (region,_) (D.Type name boundVars ctors)) =
624checkTypeVarsInUnion (A.A (region,_) (D.Type name boundVars ctors)) =
625+ do allFreeVars <- concat <$> traverse freeVars (concatMap snd ctors)
625− case diff boundVars (concatMap freeVars (concatMap snd ctors)) of
626+ case diff boundVars allFreeVars of
626− (_, []) ->
627+ (_, []) ->
627− return ()
628+ return ()
629− (_, unbound) ->
630+ (_, unbound) ->
630− Result.throw region
631+ Result.throw region
631− (Error.UnboundTypeVarsInUnion name boundVars unbound)
632+ (Error.UnboundTypeVarsInUnion name boundVars unbound)
634checkTypeVarsInAlias :: A.Commented (D.Alias Type.Raw) -> Result wrn ()
635checkTypeVarsInAlias :: A.Commented (D.Alias Type.Raw) -> Result wrn ()
635checkTypeVarsInAlias (A.A (region,_) (D.Type name boundVars tipe)) =
636checkTypeVarsInAlias (A.A (region,_) (D.Type name boundVars tipe)) =
637+ do allFreeVars <- freeVars tipe
636− case diff boundVars (freeVars tipe) of
638+ case diff boundVars allFreeVars of
637− ([], []) ->
639+ ([], []) ->
638− return ()
640+ return ()
640− ([], unbound) ->
642+ ([], unbound) ->
641− Result.throw region
643+ Result.throw region
642− (Error.UnboundTypeVarsInAlias name boundVars unbound)
644+ (Error.UnboundTypeVarsInAlias name boundVars unbound)
644− (unused, []) ->
646+ (unused, []) ->
645− Result.throw region
647+ Result.throw region
646− (Error.UnusedTypeVarsInAlias name boundVars unused)
648+ (Error.UnusedTypeVarsInAlias name boundVars unused)
648− (unused, unbound) ->
650+ (unused, unbound) ->
649− Result.throw region
651+ Result.throw region
650− (Error.MessyTypeVarsInAlias name boundVars unused unbound)
652+ (Error.MessyTypeVarsInAlias name boundVars unused unbound)
653diff :: [String] -> [A.Located String] -> ([String], [String])
655diff :: [String] -> [A.Located String] -> ([String], [String])
@@ -664,21 +666,22 @@ diff left right =
667−freeVars :: Type.Raw -> [A.Located String]
669+freeVars :: Type.Raw -> Result wrn [A.Located String]
668freeVars (A.A region tipe) =
670freeVars (A.A region tipe) =
669 case tipe of
671 case tipe of
670 Type.RLambda t1 t2 ->
672 Type.RLambda t1 t2 ->
671− freeVars t1 ++ freeVars t2
673+ (++) <$> freeVars t1 <*> freeVars t2
673 Type.RVar x ->
675 Type.RVar x ->
674− [A.A region x]
676+ Result.ok [A.A region x]
676 Type.RType _ ->
678 Type.RType _ ->
679 Type.RApp t ts ->
681 Type.RApp t ts ->
680− concatMap freeVars (t:ts)
682+ concat <$> traverse freeVars (t:ts)
682 Type.RRecord fields ext ->
684 Type.RRecord fields ext ->
683− maybe [] freeVars ext
685+ do checkDuplicateFields region fields
684− ++ concatMap (freeVars . snd) fields
686+ let types = Maybe.maybeToList ext ++ map snd fields
687+ concat <$> traverse freeVars types