aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2023-04-02 12:08:24 -0400
committerEli Schwartz <eschwartz@archlinux.org>2023-04-04 15:06:17 -0400
commit8fc4649bfe7c0cad389769624e690e4fbf0f186f (patch)
treed1073bf10e7856e12934814ad5b89aa254ec5630 /mesonbuild
parent5fe7ecb861325dd8e88eedde4769269c6a10ccf0 (diff)
downloadmeson-8fc4649bfe7c0cad389769624e690e4fbf0f186f.zip
meson-8fc4649bfe7c0cad389769624e690e4fbf0f186f.tar.gz
meson-8fc4649bfe7c0cad389769624e690e4fbf0f186f.tar.bz2
propagate the most accurate node to error messages
During evaluation of codeblocks, we start off with an iteration of nodes, and then while evaluating them we may update the global self.current_node context. When catching and formatting errors, we didn't take into account that the node might be updated from the original top-level iteration. Switch to formatting errors using self.current_node instead, to ensure we can point at the likely most-accurate actual cause of an error. Also update the current node in a few more places, so that function calls always see the function call as the current node, even if the most recently parsed node was an argument to the function call. Fixes #11643
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/interpreterbase/interpreterbase.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py
index 61b3f90..b1d0779 100644
--- a/mesonbuild/interpreterbase/interpreterbase.py
+++ b/mesonbuild/interpreterbase/interpreterbase.py
@@ -183,8 +183,9 @@ class InterpreterBase:
except Exception as e:
if getattr(e, 'lineno', None) is None:
# We are doing the equivalent to setattr here and mypy does not like it
- e.lineno = cur.lineno # type: ignore
- e.colno = cur.colno # type: ignore
+ # NOTE: self.current_node is continually updated during processing
+ e.lineno = self.current_node.lineno # type: ignore
+ e.colno = self.current_node.colno # type: ignore
e.file = os.path.join(self.source_root, self.subdir, environment.build_filename) # type: ignore
raise e
i += 1 # In THE FUTURE jump over blocks and stuff.
@@ -516,6 +517,7 @@ class InterpreterBase:
func_args = flatten(posargs)
if not getattr(func, 'no-second-level-holder-flattening', False):
func_args, kwargs = resolve_second_level_holders(func_args, kwargs)
+ self.current_node = node
res = func(node, func_args, kwargs)
return self._holderify(res) if res is not None else None
else:
@@ -544,7 +546,7 @@ class InterpreterBase:
self.validate_extraction(obj.held_object)
elif not isinstance(obj, Disabler):
raise InvalidArguments(f'Invalid operation "extract_objects" on {object_display_name} of type {type(obj).__name__}')
- obj.current_node = node
+ obj.current_node = self.current_node = node
res = obj.method_call(method_name, args, kwargs)
return self._holderify(res) if res is not None else None
@@ -598,6 +600,7 @@ class InterpreterBase:
reduced_val = self.evaluate_statement(val)
if reduced_val is None:
raise InvalidArguments(f'Value of key {reduced_key} is void.')
+ self.current_node = key
if duplicate_key_error and reduced_key in reduced_kw:
raise InvalidArguments(duplicate_key_error.format(reduced_key))
reduced_kw[reduced_key] = reduced_val