aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-01-23 20:00:00 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2017-01-23 22:02:37 +0200
commit8ec9b0a71ffa1043b17a11e594219971c9288600 (patch)
tree9af061db5305e1724779524bf90788eafdc59b35
parent8e9f0c954c08d959eb5ed52b726ab03855968cec (diff)
downloadmeson-8ec9b0a71ffa1043b17a11e594219971c9288600.zip
meson-8ec9b0a71ffa1043b17a11e594219971c9288600.tar.gz
meson-8ec9b0a71ffa1043b17a11e594219971c9288600.tar.bz2
Better error message when using = rather than : for defining keywords.
-rw-r--r--mesonbuild/interpreterbase.py10
-rw-r--r--mesonbuild/mparser.py2
-rw-r--r--test cases/failing/41 kwarg assign/dummy.c3
-rw-r--r--test cases/failing/41 kwarg assign/meson.build4
-rw-r--r--test cases/failing/41 kwarg assign/prog.c3
5 files changed, 19 insertions, 3 deletions
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index e4dd58b..837a4f8 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -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:
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py
index 5871f65..6e1e398 100644
--- a/mesonbuild/mparser.py
+++ b/mesonbuild/mparser.py
@@ -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.
diff --git a/test cases/failing/41 kwarg assign/dummy.c b/test cases/failing/41 kwarg assign/dummy.c
new file mode 100644
index 0000000..16fcdd9
--- /dev/null
+++ b/test cases/failing/41 kwarg assign/dummy.c
@@ -0,0 +1,3 @@
+const char* dummy() {
+ return "I do nothing.";
+}
diff --git a/test cases/failing/41 kwarg assign/meson.build b/test cases/failing/41 kwarg assign/meson.build
new file mode 100644
index 0000000..c86786f
--- /dev/null
+++ b/test cases/failing/41 kwarg assign/meson.build
@@ -0,0 +1,4 @@
+project('assign in kwarg', 'c')
+
+executable('prog', 'dummy.c', args = 'prog.c')
+
diff --git a/test cases/failing/41 kwarg assign/prog.c b/test cases/failing/41 kwarg assign/prog.c
new file mode 100644
index 0000000..11b7fad
--- /dev/null
+++ b/test cases/failing/41 kwarg assign/prog.c
@@ -0,0 +1,3 @@
+int main(int argc, char **argv) {
+ return 0;
+}