on master help sign in
Create error messages for bad effect manager functions
commit59f162b95dcff4fec61d48bf1895f37c060dce5c authorEvan Czaplicki <info@elm-lang.org> dateSat 5 Mar 2016, 14:55 (11 years ago) parentc37875c
2 files changed+47−6
src/Reporting/Error/Type.hs+40 src/Type/Constrain/Effects.hs+7−6
src/Reporting/Error/Type.hs+40
@@ -72,6 +72,10 @@ data Hint
7272 | Range
7373 | Lambda
7474 | Record
75+ -- effect manager problems
76+ | Manager String
77+ | State String
78+ | SelfMsg
7579
7680
7781data Pattern
@@ -425,6 +429,42 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
425429 []
426430 )
427431
432+ Manager name ->
433+ report
434+ Nothing
435+ ("The `" ++ name ++ "` in your effect manager has a weird type.")
436+ ( cmpHint
437+ ("Your `" ++ name ++ "` function has this type:")
438+ "But it needs to have a type like this:"
439+ []
440+ )
441+
442+ State name ->
443+ report
444+ Nothing
445+ ( "Your effect manager creates a certain type of state with `init`, but your `"
446+ ++ name ++ "` function expects a different kind of state."
447+ )
448+ ( cmpHint
449+ "The state created by `init` has this type:"
450+ ("But the state updated by `" ++ name ++ "` has this type:")
451+ [ "Just get the state to be the same type in both functions and you should be all set!"
452+ ]
453+ )
454+
455+ SelfMsg ->
456+ report
457+ Nothing
458+ "Effect managers can send messages to themselves, but `onEffects` and `onSelfMsg` are defined for different types of self messages."
459+ ( cmpHint
460+ "The `onEffects` function can send this type of message:"
461+ "But the `onSelfMsg` function receives this type:"
462+ [ "Just get the message type to be the same in both functions and you should be all set!"
463+ ]
464+ )
465+
466+
467+
428468
429469comparisonHint
430470 :: RenderType.Localizer
src/Type/Constrain/Effects.hs+7−6
@@ -6,6 +6,7 @@ import qualified Data.Map as Map
66import qualified AST.Effects as Fx
77import qualified AST.Module.Name as ModuleName
88import qualified Reporting.Annotation as A
9+import qualified Reporting.Error.Type as Error
910import qualified Type.Environment as Env
1011import Type.Type
1112 ( Variable, Type, TypeConstraint, Constraint(..), Scheme(Scheme)
@@ -73,12 +74,12 @@ constrainHelp env moduleName (Fx.Info tagRegion r0 r1 r2 managerType) =
7374 [ CInstance tagRegion "init" (VarN v0)
7475 , CInstance tagRegion "onEffects" (VarN v1)
7576 , CInstance tagRegion "onSelfMsg" (VarN v2)
76− , CEqual (error "TODO 1") r0 (VarN v0) (task state0)
77− , CEqual (error "TODO 2") r1 (VarN v1) onEffectsType
78− , CEqual (error "TODO 3") r2 (VarN v2) onSelfMsgType
79− , CEqual (error "TODO 4") r1 (VarN state0) (VarN state1)
80− , CEqual (error "TODO 5") r2 (VarN state0) (VarN state2)
81− , CEqual (error "TODO 6") r2 (VarN selfMsg1) (VarN selfMsg2)
77+ , CEqual (Error.Manager "init") r0 (VarN v0) (task state0)
78+ , CEqual (Error.Manager "onEffects") r1 (VarN v1) onEffectsType
79+ , CEqual (Error.Manager "onSelfMsg") r2 (VarN v2) onSelfMsgType
80+ , CEqual (Error.State "onEffects") r1 (VarN state0) (VarN state1)
81+ , CEqual (Error.State "onSelfMsg") r2 (VarN state0) (VarN state2)
82+ , CEqual Error.SelfMsg r2 (VarN selfMsg1) (VarN selfMsg2)
8283 ]
8384
8485 return $