@@ -21,8 +21,9 @@ module Language.PureScript.Errors where
2121import Prelude ()
2222import Prelude.Compat
2323
24+import Data.Ord (comparing)
2425import Data.Either (lefts, rights)
25−import Data.List (intercalate, transpose, nub, nubBy)
26+import Data.List (intercalate, transpose, nub, nubBy, sortBy)
2627import Data.Function (on)
2728import Data.Foldable (fold)
2829
@@ -32,7 +33,7 @@ import Control.Monad
3233import Control.Monad.Writer
3334import Control.Monad.Error.Class (MonadError(..))
3435import Control.Monad.Trans.State.Lazy
35−import Control.Arrow (first)
36+import Control.Arrow (first, (&&&))
3637
3738import Language.PureScript.Crash
3839import Language.PureScript.AST
@@ -141,6 +142,7 @@ data SimpleErrorMessage
141142 | UnusedExplicitImport ModuleName [String]
142143 | UnusedDctorImport ProperName
143144 | UnusedDctorExplicitImport ProperName [ProperName]
145+ | DeprecatedQualifiedSyntax ModuleName ModuleName
144146 deriving (Show)
145147
146148-- | Error message hints, providing more detailed information about failure.
@@ -275,6 +277,7 @@ errorCode em = case unwrapErrorMessage em of
275277 UnusedExplicitImport{} -> "UnusedExplicitImport"
276278 UnusedDctorImport{} -> "UnusedDctorImport"
277279 UnusedDctorExplicitImport{} -> "UnusedDctorExplicitImport"
280+ DeprecatedQualifiedSyntax{} -> "DeprecatedQualifiedSyntax"
278281
279282
280283-- |
@@ -520,12 +523,31 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
520523 <> foldMap (\expr -> [ line "Relevant expression: "
521524 , indent $ prettyPrintValue valueDepth expr
522525 ]) binding
523− renderSimpleErrorMessage (TypesDoNotUnify t1 t2)
524− = paras [ line "Could not match type"
525− , indent $ typeAsBox t1
526− , line "with type"
527− , indent $ typeAsBox t2
528− ]
526+ renderSimpleErrorMessage (TypesDoNotUnify u1 u2)
527+ = let (sorted1, sorted2) = sortRows u1 u2
528+
529+ sortRows :: Type -> Type -> (Type, Type)
530+ sortRows r1@RCons{} r2@RCons{} = sortRows' (rowToList r1) (rowToList r2)
531+ sortRows t1 t2 = (t1, t2)
532+
533+ -- Put the common labels last
534+ sortRows' :: ([(String, Type)], Type) -> ([(String, Type)], Type) -> (Type, Type)
535+ sortRows' (s1, r1) (s2, r2) =
536+ let common :: [(String, (Type, Type))]
537+ common = sortBy (comparing fst) $ [ (name, (t1, t2)) | (name, t1) <- s1, (name', t2) <- s2, name == name' ]
538+
539+ sd1, sd2 :: [(String, Type)]
540+ sd1 = [ (name, t1) | (name, t1) <- s1, name `notElem` map fst s2 ]
541+ sd2 = [ (name, t2) | (name, t2) <- s2, name `notElem` map fst s1 ]
542+ in ( rowFromList (sortBy (comparing fst) sd1 ++ map (fst &&& fst . snd) common, r1)
543+ , rowFromList (sortBy (comparing fst) sd2 ++ map (fst &&& snd . snd) common, r2)
544+ )
545+ in paras [ line "Could not match type"
546+ , indent $ typeAsBox sorted1
547+ , line "with type"
548+ , indent $ typeAsBox sorted2
549+ ]
550+
529551 renderSimpleErrorMessage (KindsDoNotUnify k1 k2) =
530552 paras [ line "Could not match kind"
531553 , indent $ line $ prettyPrintKind k1
@@ -692,6 +714,10 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
692714 paras [ line $ "The import of type " ++ runProperName name ++ " includes the following unused data constructors:"
693715 , indent $ paras $ map (line .runProperName) names ]
694716
717+ renderSimpleErrorMessage (DeprecatedQualifiedSyntax name qualName) =
718+ paras [ line $ "The import of type " ++ runModuleName name ++ " as " ++ runModuleName qualName ++ " uses the deprecated 'import qualified' syntax."
719+ , line $ "This syntax form will be removed in PureScript 0.9." ]
720+
695721 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
696722 renderHint (ErrorUnifyingTypes t1 t2) detail =
697723 paras [ detail