Better error message when using = rather than : for defining keywords.

pull/1332/head
Jussi Pakkanen 8 years ago
parent 8e9f0c954c
commit 8ec9b0a71f
  1. 10
      mesonbuild/interpreterbase.py
  2. 2
      mesonbuild/mparser.py
  3. 3
      test cases/failing/41 kwarg assign/dummy.c
  4. 4
      test cases/failing/41 kwarg assign/meson.build
  5. 3
      test cases/failing/41 kwarg assign/prog.c

@ -1,4 +1,4 @@
# Copyright 2016 The Meson development team
# Copyright 2016-2017 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -86,6 +86,7 @@ class InterpreterBase:
self.builtin = {}
self.subdir = subdir
self.variables = {}
self.argument_depth = 0
def load_root_meson_file(self):
mesonfile = os.path.join(self.source_root, self.subdir, environment.build_filename)
@ -511,6 +512,7 @@ class InterpreterBase:
assert(isinstance(args, mparser.ArgumentNode))
if args.incorrect_order():
raise InvalidArguments('All keyword arguments must be after positional arguments.')
self.argument_depth += 1
reduced_pos = [self.evaluate_statement(arg) for arg in args.arguments]
reduced_kw = {}
for key in args.kwargs.keys():
@ -520,6 +522,7 @@ class InterpreterBase:
reduced_kw[key] = self.evaluate_statement(a)
if not isinstance(reduced_pos, list):
reduced_pos = [reduced_pos]
self.argument_depth -= 1
return reduced_pos, reduced_kw
def flatten(self, args):
@ -540,6 +543,9 @@ class InterpreterBase:
def assignment(self, node):
assert(isinstance(node, mparser.AssignmentNode))
if self.argument_depth != 0:
raise InvalidArguments('''Tried to assign values inside an argument list.
To specify a keyword argument, use : instead of =.''')
var_name = node.var_name
if not isinstance(var_name, str):
raise InvalidArguments('Tried to assign value to a non-variable.')
@ -551,7 +557,7 @@ class InterpreterBase:
if isinstance(value, MutableInterpreterObject):
value = copy.deepcopy(value)
self.set_variable(var_name, value)
return value
return None
def set_variable(self, varname, variable):
if variable is None:

@ -1,4 +1,4 @@
# Copyright 2014-2016 The Meson development team
# Copyright 2014-2017 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

@ -0,0 +1,3 @@
const char* dummy() {
return "I do nothing.";
}

@ -0,0 +1,4 @@
project('assign in kwarg', 'c')
executable('prog', 'dummy.c', args = 'prog.c')

@ -0,0 +1,3 @@
int main(int argc, char **argv) {
return 0;
}
Loading…
Cancel
Save