1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Nitpick.TopLevelTypes (topLevelTypes) where
5import qualified Data.Foldable as F
7import qualified Data.Map as Map
8import qualified Data.Text as Text
11import qualified AST.Expression.Canonical as Can
12import qualified AST.Module.Name as ModuleName
13import qualified AST.Pattern as P
14import qualified AST.Type as Type
15import qualified AST.Variable as Var
16import qualified Canonicalize.Effects as Effects
17import qualified Elm.Package as Pkg
18import qualified Reporting.Annotation as A
19import qualified Reporting.Error.Type as Error
20import qualified Reporting.Result as Result
21import qualified Reporting.Warning as Warning
26 Result.Result () Warning.Warning Error.Error
30 Map.Map Text Type.Canonical
34-- CHECK TOP LEVEL TYPES
37topLevelTypes :: TypeDict -> Can.SortedDefs -> Result [Can.Def]
38topLevelTypes typeEnv sortedDefs =
41 checkAnnotation typeEnv
46 <* F.traverse_ check defs
48 Can.YesMain before main after ->
50 <* F.traverse_ check before
51 <* F.traverse_ check after
53 mainDef <- checkMain typeEnv main
55 return (before ++ mainDef : after)
62checkAnnotation :: TypeDict -> Can.Def -> Result ()
63checkAnnotation typeEnv (Can.Def _ (A.A region pattern) _ maybeType) =
64 case (pattern, maybeType) of
65 (P.Var name, Nothing) ->
68 Warning.MissingTypeAnnotation (Text.unpack name) (typeEnv ! name)
70 Result.warn region warning ()
80checkMain :: TypeDict -> Can.Def -> Result Can.Def
81checkMain typeEnv (Can.Def facts pattern@(A.A region _) body maybeType) =
86 makeError tipe maybeMsg =
87 A.A region (Error.BadFlags tipe maybeMsg)
90 case Type.deepDealias mainType of
95 Type.App name [flags, _, _]
96 | name == program && flags == never ->
100 return (Can.Flags flags)
101 <* Effects.checkPortType makeError flags
104 Result.throw region (Error.BadMain mainType)
106 do kind <- getMainKind
107 let newBody = A.A undefined (Can.Program kind body)
108 return (Can.Def facts pattern newBody maybeType)
111program :: Type.Canonical
113 Type.Type (Var.inCore "Platform" "Program")
116never :: Type.Canonical
118 Type.Type (Var.inCore "Basics" "Never")
121vdomNode :: Type.Canonical
125 ModuleName.Canonical Pkg.virtualDom "VirtualDom"
127 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