Merge pull request #96 from madjar/default-args-in-atpattern

Fix a bug where defaultargs are absent from the atpattern argument
This commit is contained in:
Georges Dubus 2018-03-11 12:16:01 +01:00 committed by GitHub
commit 9cd901fc4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View file

@ -98,9 +98,10 @@ buildArgument paramSpec arg = either error id $ case paramSpec of
let actualParamSet = case paramSet of
FixedParamSet s -> s
VariadicParamSet s -> s
maybeAddSet = case setName of
Just name -> Map.insert name arg
Nothing -> id
maybeAddSet attrsSet = case setName of
Just name -> let Fix (NVSet argSet) = arg
in Map.insert name (Fix (NVSet (argSet `Map.union` attrsSet))) attrsSet
Nothing -> attrsSet
in maybeAddSet <$> lookupParamSet actualParamSet
where
go env k def = maybe (Left err) return $ Map.lookup k env <|> def

View file

@ -42,6 +42,9 @@ case_function_atpattern = constantEqualStr "2" "(({a}@attrs:attrs) {a=2;}).a"
case_function_ellipsis :: Assertion
case_function_ellipsis = constantEqualStr "2" "(({a, ...}@attrs:attrs) {a=0; b=2;}).b"
case_function_default_value_in_atpattern :: Assertion
case_function_default_value_in_atpattern = constantEqualStr "2" "({a ? 2}@attrs:attrs.a) {}"
tests :: TestTree
tests = $testGroupGenerator