1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Nitpick.TopLevelTypes (topLevelTypes) where
5import qualified Data.Foldable as F
7import qualified Data.Map as Map
10import qualified AST.Expression.Canonical as Can
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 Canonicalize.Effects as Effects
16import qualified Elm.Package as Pkg
17import qualified Reporting.Annotation as A
18import qualified Reporting.Error.Type as Error
19import qualified Reporting.Result as Result
20import qualified Reporting.Warning as Warning
25 Result.Result () Warning.Warning Error.Error
29 Map.Map Text Type.Canonical
33-- CHECK TOP LEVEL TYPES
36topLevelTypes :: TypeDict -> Can.SortedDefs -> Result [Can.Def]
37topLevelTypes typeEnv sortedDefs =
40 checkAnnotation typeEnv
45 <* F.traverse_ check defs
47 Can.YesMain before main after ->
49 <* F.traverse_ check before
50 <* F.traverse_ check after
52 mainDef <- checkMain typeEnv main
54 return (before ++ mainDef : after)
61checkAnnotation :: TypeDict -> Can.Def -> Result ()
62checkAnnotation typeEnv (Can.Def _ (A.A region pattern) _ maybeType) =
63 case (pattern, maybeType) of
64 (P.Var name, Nothing) ->
67 Warning.MissingTypeAnnotation name (typeEnv ! name)
69 Result.warn region warning ()
79checkMain :: TypeDict -> Can.Def -> Result Can.Def
80checkMain typeEnv (Can.Def facts pattern@(A.A region _) body maybeType) =
85 makeError tipe maybeMsg =
86 A.A region (Error.BadFlags tipe maybeMsg)
89 case Type.deepDealias mainType of
94 Type.App name [flags, _, _]
95 | name == program && flags == never ->
99 return (Can.Flags flags)
100 <* Effects.checkPortType makeError flags
103 Result.throw region (Error.BadMain mainType)
105 do kind <- getMainKind
106 let newBody = A.A undefined (Can.Program kind body)
107 return (Can.Def facts pattern newBody maybeType)
110program :: Type.Canonical
112 Type.Type (Var.inCore "Platform" "Program")
115never :: Type.Canonical
117 Type.Type (Var.inCore "Basics" "Never")
120vdomNode :: Type.Canonical
124 ModuleName.Canonical Pkg.virtualDom "VirtualDom"
126 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