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.Expression.General as Expr
10import qualified AST.Module.Name as ModuleName
11import qualified AST.Pattern as P
12import qualified AST.Type as Type
13import qualified AST.Variable as Var
14import qualified Canonicalize.Effects as Effects
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 Result.Result () Warning.Warning Error.Error
28 Map.Map String Type.Canonical
32-- CHECK TOP LEVEL TYPES
35topLevelTypes :: TypeDict -> Can.SortedDefs -> Result [Can.Def]
36topLevelTypes typeEnv sortedDefs =
39 checkAnnotation typeEnv
44 <* F.traverse_ check defs
46 Can.YesMain before main after ->
48 <* F.traverse_ check before
49 <* F.traverse_ check after
51 mainDef <- checkMain typeEnv main
53 return (before ++ mainDef : after)
60checkAnnotation :: TypeDict -> Can.Def -> Result ()
61checkAnnotation typeEnv (Can.Def _ (A.A region pattern) _ maybeType) =
62 case (pattern, maybeType) of
63 (P.Var name, Nothing) ->
66 Warning.MissingTypeAnnotation name (typeEnv ! name)
68 Result.warn region warning ()
78checkMain :: TypeDict -> Can.Def -> Result Can.Def
79checkMain typeEnv (Can.Def facts pattern@(A.A region _) body maybeType) =
84 makeError tipe maybeMsg =
85 A.A region (Error.BadFlags tipe maybeMsg)
88 case Type.deepDealias mainType of
93 | name == program && arg == never ->
97 return (Expr.Flags arg)
98 <* Effects.checkForeignType makeError arg
101 Result.throw region (Error.BadMain mainType)
103 do kind <- getMainKind
104 let newBody = A.A undefined (Expr.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