@@ -1,8 +1,7 @@
11{-# OPTIONS_GHC -Wall #-}
22module Validate (Result, module') where
33
4−import Prelude hiding (init)
5−import Control.Monad (foldM, when)
4+import Control.Monad (foldM_, when)
65import qualified Data.Map as Map
76import qualified Data.Maybe as Maybe
87import qualified Data.Set as Set
@@ -428,8 +427,8 @@ validateDefPattern pattern body =
428427
429428 args ->
430429 case pattern of
431− A.A _ (Pattern.Var _) ->
432− return ()
430+ A.A _ (Pattern.Var funcName) ->
431+ checkArguments funcName args
433432
434433 _ ->
435434 let
@@ -439,6 +438,22 @@ validateDefPattern pattern body =
439438 Result.throw (R.merge start end) (Error.BadFunctionName (length args))
440439
441440
441+checkArguments :: String -> [Pattern.Raw] -> Result wrn ()
442+checkArguments funcName args =
443+ let
444+ vars =
445+ concatMap Pattern.boundVars args
446+
447+ checkDups seenArgs (A.A region arg) =
448+ if Set.member arg seenArgs then
449+ Result.throw region (Error.DuplicateArgument funcName arg)
450+
451+ else
452+ return (Set.insert arg seenArgs)
453+ in
454+ foldM_ checkDups Set.empty vars
455+
456+
442457
443458-- VALIDATE EXPRESSIONS
444459
@@ -509,7 +524,7 @@ expression (A.A ann sourceExpression) =
509524 else
510525 return (Set.insert field seenFields)
511526 in
512− do _ <- foldM checkDups Set.empty fields
527+ do foldM_ checkDups Set.empty fields
513528 Record <$> T.traverse second fields
514529
515530 Let defs body ->