1{-# OPTIONS_GHC -Wall #-}
2module Nitpick.TopLevelTypes (topLevelTypes) where
4import qualified Data.Foldable as F
6import qualified Data.Map as Map
8import qualified AST.Expression.Canonical as Can
9import qualified AST.Module.Name as ModuleName
10import qualified AST.Pattern as P
11import qualified AST.Type as Type
12import qualified AST.Variable as Var
13import qualified Canonicalize.Effects as Effects
14import qualified Elm.Package as Pkg
15import qualified Reporting.Annotation as A
16import qualified Reporting.Error.Type as Error
17import qualified Reporting.Result as Result
18import qualified Reporting.Warning as Warning
23 Result.Result () Warning.Warning Error.Error
27 Map.Map String Type.Canonical
31-- CHECK TOP LEVEL TYPES
34topLevelTypes :: TypeDict -> Can.SortedDefs -> Result [Can.Def]
35topLevelTypes typeEnv sortedDefs =
38 checkAnnotation typeEnv
43 <* F.traverse_ check defs
45 Can.YesMain before main after ->
47 <* F.traverse_ check before
48 <* F.traverse_ check after
50 mainDef <- checkMain typeEnv main
52 return (before ++ mainDef : after)
59checkAnnotation :: TypeDict -> Can.Def -> Result ()
60checkAnnotation typeEnv (Can.Def _ (A.A region pattern) _ maybeType) =
61 case (pattern, maybeType) of
62 (P.Var name, Nothing) ->
65 Warning.MissingTypeAnnotation name (typeEnv ! name)
67 Result.warn region warning ()
77checkMain :: TypeDict -> Can.Def -> Result Can.Def
78checkMain typeEnv (Can.Def facts pattern@(A.A region _) body maybeType) =
83 makeError tipe maybeMsg =
84 A.A region (Error.BadFlags tipe maybeMsg)
87 case Type.deepDealias mainType of
92 Type.App name [flags, _, _]
93 | name == program && flags == never ->
97 return (Can.Flags flags)
98 <* Effects.checkPortType makeError flags
101 Result.throw region (Error.BadMain mainType)
103 do kind <- getMainKind
104 let newBody = A.A undefined (Can.Program kind body)
105 return (Can.Def facts pattern newBody maybeType)
108program :: Type.Canonical
110 Type.Type (Var.inCore ["Platform"] "Program")
113never :: Type.Canonical
115 Type.Type (Var.inCore ["Basics"] "Never")
118vdomNode :: Type.Canonical
122 ModuleName.Canonical Pkg.virtualDom ["VirtualDom"]
124 Type.Type (Var.fromModule vdom "Node")
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