compiler: reject calls with unexpected keyword arguments.

Fixes #924.
This commit is contained in:
whitequark 2018-02-21 11:37:12 +00:00
parent 7986391422
commit 86ceee570f
2 changed files with 14 additions and 0 deletions

View File

@ -1004,6 +1004,17 @@ class Inferencer(algorithm.Visitor):
elif keyword.arg in typ_optargs: elif keyword.arg in typ_optargs:
self._unify(keyword.value.type, typ_optargs[keyword.arg], self._unify(keyword.value.type, typ_optargs[keyword.arg],
keyword.value.loc, None) keyword.value.loc, None)
else:
note = diagnostic.Diagnostic("note",
"extraneous argument", {},
keyword.loc)
diag = diagnostic.Diagnostic("error",
"this function of type {type} does not accept argument '{name}'",
{"type": types.TypePrinter().name(node.func.type),
"name": keyword.arg},
node.func.loc, [], [note])
self.engine.process(diag)
return
passed_args[keyword.arg] = keyword.arg_loc passed_args[keyword.arg] = keyword.arg_loc
for formalname in typ_args: for formalname in typ_args:

View File

@ -18,3 +18,6 @@ f(1, x=1)
# CHECK-L: ${LINE:+1}: error: mandatory argument 'x' is not passed # CHECK-L: ${LINE:+1}: error: mandatory argument 'x' is not passed
f() f()
# CHECK: ${LINE:+1}: error: this function of type .* does not accept argument 'q'
f(1, q=1)