@@ -20,6 +20,7 @@ import qualified Canonicalize.Type as Type
20import qualified Elm.Name as N
20import qualified Elm.Name as N
21import qualified Reporting.Annotation as A
21import qualified Reporting.Annotation as A
22import qualified Reporting.Error.Canonicalize as Error
22import qualified Reporting.Error.Canonicalize as Error
23+import qualified Reporting.Region as R
23import qualified Reporting.Result as Result
24import qualified Reporting.Result as Result
24import qualified Reporting.Warning as Warning
25import qualified Reporting.Warning as Warning
@@ -36,8 +37,13 @@ type Result a =
36-- CANONICALIZE
37-- CANONICALIZE
42+ -> [A.Located Valid.Decl]
43+ -> Map.Map N.Name union
39−canonicalize :: Env.Env -> Map.Map N.Name a -> Valid.Effects -> Result Can.Effects
45+ -> Result Can.Effects
40−canonicalize env unions effects =
46+canonicalize env decls unions effects =
41 case effects of
47 case effects of
42 Valid.NoEffects ->
48 Valid.NoEffects ->
43 Result.ok Can.NoEffects
49 Result.ok Can.NoEffects
@@ -46,24 +52,28 @@ canonicalize env unions effects =
46 do pairs <- traverse (canonicalizePort env) ports
52 do pairs <- traverse (canonicalizePort env) ports
47 return $ Can.Ports (Map.fromList pairs)
53 return $ Can.Ports (Map.fromList pairs)
55+ Valid.Manager region manager ->
56+ let dict = Map.fromList (map toNameRegion decls) in
58+ <$> verifyManager region dict "init"
59+ <*> verifyManager region dict "onEffects"
60+ <*> verifyManager region dict "onSelfMsg"
49− Valid.Cmd cmdType ->
63+ Valid.Cmd cmdType ->
50− Can.Cmd <$> verifyEffectType cmdType unions
64+ Can.Cmd <$> verifyEffectType cmdType unions
52− Valid.Sub subType ->
66+ Valid.Sub subType ->
53− Can.Sub <$> verifyEffectType subType unions
67+ Can.Sub <$> verifyEffectType subType unions
55− Valid.Fx cmdType subType ->
69+ Valid.Fx cmdType subType ->
57− <$> verifyEffectType cmdType unions
71+ <$> verifyEffectType cmdType unions
58− <*> verifyEffectType subType unions
72+ <*> verifyEffectType subType unions
61−verifyEffectType :: A.Located N.Name -> Map.Map N.Name a -> Result N.Name
75+
62−verifyEffectType (A.A region name) unions =
76+-- CANONICALIZE PORT
63− if Map.member name unions then
66− Result.throw region (Error.EffectNotFound name)
69canonicalizePort :: Env.Env -> Valid.Port -> Result (N.Name, Can.Port)
79canonicalizePort :: Env.Env -> Valid.Port -> Result (N.Name, Can.Port)
@@ -93,6 +103,33 @@ canonicalizePort env (Valid.Port (A.A region portName) tipe) =
109+verifyEffectType :: A.Located N.Name -> Map.Map N.Name a -> Result N.Name
110+verifyEffectType (A.A region name) unions =
111+ if Map.member name unions then
114+ Result.throw region (Error.EffectNotFound name)
117+toNameRegion :: A.Located Valid.Decl -> (N.Name, R.Region)
118+toNameRegion (A.A _ (Valid.Decl (A.A region name) _ _ _)) =
122+verifyManager :: R.Region -> Map.Map N.Name R.Region -> N.Name -> Result R.Region
123+verifyManager tagRegion decls name =
124+ case Map.lookup name decls of
129+ Result.throw tagRegion (Error.EffectFunctionNotFound name)
96-- CHECK PAYLOAD TYPES
133-- CHECK PAYLOAD TYPES