From c0efa7ab22f8900f6fa1dadf0d306ec375569c8d Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sun, 12 Sep 2021 16:53:54 +0200 Subject: [PATCH] interpreter: Add FeatureNew check --- mesonbuild/interpreter/primitives/string.py | 12 ++++++++++++ test cases/common/35 string operations/meson.build | 2 +- test cases/common/35 string operations/test.json | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test cases/common/35 string operations/test.json diff --git a/mesonbuild/interpreter/primitives/string.py b/mesonbuild/interpreter/primitives/string.py index 82da6ce24..d9c441a9a 100644 --- a/mesonbuild/interpreter/primitives/string.py +++ b/mesonbuild/interpreter/primitives/string.py @@ -21,6 +21,11 @@ from ...interpreterbase import ( InvalidArguments, ) +from ...mparser import ( + MethodNode, + StringNode, + ArrayNode, +) if T.TYPE_CHECKING: @@ -105,6 +110,13 @@ class StringHolder(ObjectHolder[str]): @noKwargs @typed_pos_args('str.join', varargs=str) def join_method(self, args: T.Tuple[T.List[str]], kwargs: TYPE_kwargs) -> str: + # Implement some basic FeatureNew check on the AST level + assert isinstance(self.current_node, MethodNode) + n_args = self.current_node.args.arguments + if len(n_args) != 1 or not isinstance(n_args[0], ArrayNode) or not all(isinstance(x, StringNode) for x in n_args[0].args.arguments): + FeatureNew.single_use('str.join (varargs)', '0.60.0', self.subproject, 'List-flattening and variadic arguments') + + # Actual implementation return self.held_object.join(args[0]) @noKwargs diff --git a/test cases/common/35 string operations/meson.build b/test cases/common/35 string operations/meson.build index b86e13a1a..54eab88df 100644 --- a/test cases/common/35 string operations/meson.build +++ b/test cases/common/35 string operations/meson.build @@ -1,4 +1,4 @@ -project('string formatting', 'c') +project('string formatting', 'c', meson_version: '>=0.59.0') templ = '@0@bar@1@' diff --git a/test cases/common/35 string operations/test.json b/test cases/common/35 string operations/test.json new file mode 100644 index 000000000..96f965947 --- /dev/null +++ b/test cases/common/35 string operations/test.json @@ -0,0 +1,7 @@ +{ + "stdout": [ + { + "line": "WARNING: Project targeting '>=0.59.0' but tried to use feature introduced in '0.60.0': str.join (varargs). List-flattening and variadic arguments" + } + ] +}