1{-# OPTIONS_GHC -Wall #-}
2module Nitpick.TopLevelTypes (topLevelTypes) where
5import Prelude hiding (maybe)
6import qualified Data.Foldable as F
7import qualified Data.Map as Map
9import qualified AST.Expression.Valid as Valid
10import qualified AST.Declaration as Decl
11import qualified AST.Module.Name as ModuleName
12import qualified AST.Pattern as P
13import qualified AST.Type as Type
14import qualified AST.Variable as Var
15import qualified Elm.Package as Pkg
16import qualified Reporting.Annotation as A
17import qualified Reporting.Error.Type as Error
18import qualified Reporting.Result as Result
19import qualified Reporting.Warning as Warning
24 :: Map.Map String Type.Canonical
26 -> Result.Result Warning.Warning Error.Error ()
27topLevelTypes typeEnv validDecls =
28 do F.traverse_ (warnMissingAnnotation typeEnv) validDecls
29 checkMainType typeEnv validDecls
37 :: Map.Map String Type.Canonical
39 -> Result.Result Warning.Warning Error.Error ()
40warnMissingAnnotation typeEnv (A.A (region,_) decl) =
42 Decl.Def (Valid.Definition (A.A _ (P.Var name)) _ Nothing) ->
43 Result.warn region (Warning.MissingTypeAnnotation name (typeEnv ! name))
54 :: Map.Map String Type.Canonical
56 -> Result.Result w Error.Error ()
57checkMainType typeEnv decls =
59 A.A (region,_) (Decl.Def (Valid.Definition (A.A _ (P.Var "main")) _ _)) : _ ->
60 case Map.lookup "main" typeEnv of
65 case Type.deepDealias tipe of
66 Type.App (Type.Type name) [_] | name == virtualDomNode ->
69 Type.App (Type.Type name) [_] | name == program ->
73 Result.throw region (Error.BadMain tipe)
76 checkMainType typeEnv remainingDecls
82virtualDomNode :: Var.Canonical
85 (ModuleName.Canonical (Pkg.Name "evancz" "virtual-dom") ["VirtualDom"])
89program :: Var.Canonical
91 Var.fromModule (ModuleName.inCore ["Platform"]) "Program"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list