@@ -11,8 +11,10 @@ import qualified Data.Map as Map
11import qualified AST.Type as Type
11import qualified AST.Type as Type
12import qualified Canonicalize.Environment.Dups as Dups
12import qualified Canonicalize.Environment.Dups as Dups
13import qualified Canonicalize.Environment.Internals as Env
13import qualified Canonicalize.Environment.Internals as Env
14+import qualified Elm.Name as N
14import qualified Reporting.Annotation as A
15import qualified Reporting.Annotation as A
15import qualified Reporting.Error.Canonicalize as Error
16import qualified Reporting.Error.Canonicalize as Error
17+import qualified Reporting.Region as R
16import qualified Reporting.Result as Result
18import qualified Reporting.Result as Result
17import qualified Reporting.Warning as Warning
19import qualified Reporting.Warning as Warning
@@ -30,20 +32,21 @@ type Result i a =
32canonicalize :: Env.Env -> Type.Raw -> Result () Type.Canonical
34canonicalize :: Env.Env -> Type.Raw -> Result () Type.Canonical
33−canonicalize env (A.A _ tipe) =
35+canonicalize env (A.A typeRegion tipe) =
34 case tipe of
36 case tipe of
35 Type.RVar x ->
37 Type.RVar x ->
36 Result.ok (Type.Var x)
38 Result.ok (Type.Var x)
38 Type.RType region maybePrefix name args ->
40 Type.RType region maybePrefix name args ->
39− do info <- Env.findType region env maybePrefix name (length args)
41+ do info <- Env.findType region env maybePrefix name
40 cargs <- traverse (canonicalize env) args
42 cargs <- traverse (canonicalize env) args
42− case info of
43+ case info of
43− Env.Alias home argNames aliasedType ->
44+ Env.Alias arity home argNames aliasedType ->
45+ checkArgs Error.AliasArgs arity typeRegion name args $
44 Type.Aliased home name (zip argNames cargs) (Type.Holey aliasedType)
46 Type.Aliased home name (zip argNames cargs) (Type.Holey aliasedType)
46− Env.Union home ->
48+ Env.Union arity home ->
49+ checkArgs Error.UnionArgs arity typeRegion name args $
47 Type.Type home name cargs
50 Type.Type home name cargs
49 Type.RLambda a b ->
52 Type.RLambda a b ->
@@ -64,4 +67,36 @@ canonicalize env (A.A _ tipe) =
64 Type.Tuple
67 Type.Tuple
65 <$> canonicalize env a
68 <$> canonicalize env a
66 <*> canonicalize env b
69 <*> canonicalize env b
67− <*> traverse (canonicalize env) cs
76+ Just <$> canonicalize env c
79+ let (A.A start _, A.A end _) = (head cs, last cs) in
80+ Result.throw typeRegion $
81+ Error.TupleLargerThanThree (R.merge start end)
88+checkArgs :: Error.Args -> Int -> R.Region -> N.Name -> [A.Located arg] -> answer -> Result () answer
89+checkArgs argsType expected region name args answer =
90+ let actual = length args in
91+ if expected == actual then
94+ Result.throw region $
95+ if actual < expected then
96+ Error.TooFew argsType name expected actual
99+ extras = drop expected args
100+ (A.A start _, A.A end _) = (head extras, last extras)
102+ Error.TooMany argsType name expected actual (R.merge start end)