on master help sign in
Create error messages for bad effect manager functions
59f162bEvan Czaplicki
src/Reporting/Error/Type.hs+40
@@ -72,6 +72,10 @@ data Hint
72 | Range
72 | Range
73 | Lambda
73 | Lambda
74 | Record
74 | Record
75+ -- effect manager problems
76+ | Manager String
77+ | State String
78+ | SelfMsg
75
79
76
80
77data Pattern
81data Pattern
@@ -425,6 +429,42 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
425 []
429 []
426 )
430 )
427
431
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+
428
468
429comparisonHint
469comparisonHint
430 :: RenderType.Localizer
470 :: RenderType.Localizer
src/Type/Constrain/Effects.hs+7−6
@@ -6,6 +6,7 @@ import qualified Data.Map as Map
6import qualified AST.Effects as Fx
6import qualified AST.Effects as Fx
7import qualified AST.Module.Name as ModuleName
7import qualified AST.Module.Name as ModuleName
8import qualified Reporting.Annotation as A
8import qualified Reporting.Annotation as A
9+import qualified Reporting.Error.Type as Error
9import qualified Type.Environment as Env
10import qualified Type.Environment as Env
10import Type.Type
11import Type.Type
11 ( Variable, Type, TypeConstraint, Constraint(..), Scheme(Scheme)
12 ( Variable, Type, TypeConstraint, Constraint(..), Scheme(Scheme)
@@ -73,12 +74,12 @@ constrainHelp env moduleName (Fx.Info tagRegion r0 r1 r2 managerType) =
73 [ CInstance tagRegion "init" (VarN v0)
74 [ CInstance tagRegion "init" (VarN v0)
74 , CInstance tagRegion "onEffects" (VarN v1)
75 , CInstance tagRegion "onEffects" (VarN v1)
75 , CInstance tagRegion "onSelfMsg" (VarN v2)
76 , CInstance tagRegion "onSelfMsg" (VarN v2)
76− , CEqual (error "TODO 1") r0 (VarN v0) (task state0)
77+ , CEqual (Error.Manager "init") r0 (VarN v0) (task state0)
77− , CEqual (error "TODO 2") r1 (VarN v1) onEffectsType
78+ , CEqual (Error.Manager "onEffects") r1 (VarN v1) onEffectsType
78− , CEqual (error "TODO 3") r2 (VarN v2) onSelfMsgType
79+ , CEqual (Error.Manager "onSelfMsg") r2 (VarN v2) onSelfMsgType
79− , CEqual (error "TODO 4") r1 (VarN state0) (VarN state1)
80+ , CEqual (Error.State "onEffects") r1 (VarN state0) (VarN state1)
80− , CEqual (error "TODO 5") r2 (VarN state0) (VarN state2)
81+ , CEqual (Error.State "onSelfMsg") r2 (VarN state0) (VarN state2)
81− , CEqual (error "TODO 6") r2 (VarN selfMsg1) (VarN selfMsg2)
82+ , CEqual Error.SelfMsg r2 (VarN selfMsg1) (VarN selfMsg2)
82 ]
83 ]
83
84
84 return $
85 return $