on master help sign in
Improve error messages as described in a list discussion
b5e7311Evan Czaplicki
compiler/Type/ExtraChecks.hs+13−7
@@ -56,7 +56,7 @@ portTypes rules expr =
56 T.Data ctor ts
56 T.Data ctor ts
57 | isJs ctor || isElm ctor -> mapM_ valid ts
57 | isJs ctor || isElm ctor -> mapM_ valid ts
58 | ctor == "Signal.Signal" -> handleSignal ts
58 | ctor == "Signal.Signal" -> handleSignal ts
59− | otherwise -> err "Algebraic Data Types"
59+ | otherwise -> err' True "an unsupported type"
60
60
61 T.Var _ -> err "free type variables"
61 T.Var _ -> err "free type variables"
62
62
@@ -90,16 +90,22 @@ portTypes rules expr =
90 dir inMsg outMsg = case direction of { In -> inMsg ; Out -> outMsg }
90 dir inMsg outMsg = case direction of { In -> inMsg ; Out -> outMsg }
91 txt = P.text . concat
91 txt = P.text . concat
92
92
93− err kind =
93+ err = err' False
94+ err' couldBeAlias kind =
94 throw $
95 throw $
95 [ txt [ "Type Error: the value ", dir "coming in" "sent out"
96 [ txt [ "Type Error: the value ", dir "coming in" "sent out"
96 , " through port '", name, "' is invalid." ]
97 , " through port '", name, "' is invalid." ]
97− , txt [ "Acceptable values for ", dir "incoming" "outgoing"
98+ , txt [ "It contains ", kind, ":\n" ]
98− , " ports include JavaScript values and the following Elm values:" ]
99− , txt [ "Ints, Floats, Bools, Strings, Maybes, Lists, Tuples, "
100− , dir "" "first-order functions, ", "and concrete records." ]
101− , txt [ "The values sent through this port contain ", kind, ":\n" ]
102 , (P.nest 4 . pretty $ Alias.realias rules tipe) <> P.text "\n"
99 , (P.nest 4 . pretty $ Alias.realias rules tipe) <> P.text "\n"
100+ , txt [ "Acceptable values for ", dir "incoming" "outgoing"
101+ , " ports include JavaScript values and" ]
102+ , txt [ "the following Elm values: Ints, Floats, Bools, Strings, Maybes," ]
103+ , txt [ "Lists, Tuples, ", dir "" "first-order functions, ", "and concrete records." ]
104+ ] ++ if couldBeAlias then aliasWarning else []
105+
106+ aliasWarning =
107+ [ txt [ "\nType aliases are not expanded for this check (yet) so you need to do that" ]
108+ , txt [ "manually for now (e.g. {x:Int,y:Int} instead of a type alias of that type)." ]
103 ]
109 ]
104
110
105occurs :: (String, Variable) -> StateT TS.SolverState IO ()
111occurs :: (String, Variable) -> StateT TS.SolverState IO ()