From 86ceee570ff5850ac4df7761bcdc1356550474ed Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 21 Feb 2018 11:37:12 +0000 Subject: [PATCH] compiler: reject calls with unexpected keyword arguments. Fixes #924. --- artiq/compiler/transforms/inferencer.py | 11 +++++++++++ artiq/test/lit/inferencer/error_call.py | 3 +++ 2 files changed, 14 insertions(+) diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index 5c54f235c..7880a6390 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -1004,6 +1004,17 @@ class Inferencer(algorithm.Visitor): elif keyword.arg in typ_optargs: self._unify(keyword.value.type, typ_optargs[keyword.arg], 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 for formalname in typ_args: diff --git a/artiq/test/lit/inferencer/error_call.py b/artiq/test/lit/inferencer/error_call.py index 1c3df3a6a..1497c7821 100644 --- a/artiq/test/lit/inferencer/error_call.py +++ b/artiq/test/lit/inferencer/error_call.py @@ -18,3 +18,6 @@ f(1, x=1) # CHECK-L: ${LINE:+1}: error: mandatory argument 'x' is not passed f() + +# CHECK: ${LINE:+1}: error: this function of type .* does not accept argument 'q' +f(1, q=1)