diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2021-11-04 18:46:09 -0400 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2021-11-04 18:57:14 -0400 |
commit | 558f9fed9e4136f858b58749fd35127a73229cd2 (patch) | |
tree | 5c5256801e73b7d739b5201db6a8b36ee147abfe | |
parent | 1104b82137da55ecb4f13348bbb020d64e4fc78b (diff) | |
download | meson-558f9fed9e4136f858b58749fd35127a73229cd2.zip meson-558f9fed9e4136f858b58749fd35127a73229cd2.tar.gz meson-558f9fed9e4136f858b58749fd35127a73229cd2.tar.bz2 |
fix regression that broke string.format with list objects
String formatting should validly assume that printing a list means
printing the list itself. Instead, something like this broke:
'one is: @0@ and two is: @1@'.format(['foo', 'bar'], ['baz'])
which would evaluate as:
'one is: foo and two is: bar'
or:
'the value of array option foobar is: @0@'.format(get_option('foobar'))
which should evaluate with '-Dfoobar=[]' as
'the value of array option foobar is: []'
But instead produced:
meson.build:7:0: ERROR: Format placeholder @0@ out of range.
Fixes #9530
-rw-r--r-- | mesonbuild/interpreter/primitives/string.py | 2 | ||||
-rw-r--r-- | test cases/common/35 string operations/meson.build | 1 |
2 files changed, 3 insertions, 0 deletions
diff --git a/mesonbuild/interpreter/primitives/string.py b/mesonbuild/interpreter/primitives/string.py index 3f8df5e..a5fc992 100644 --- a/mesonbuild/interpreter/primitives/string.py +++ b/mesonbuild/interpreter/primitives/string.py @@ -13,6 +13,7 @@ from ...interpreterbase import ( MesonOperator, FeatureNew, typed_operator, + noArgsFlattening, noKwargs, noPosargs, typed_pos_args, @@ -85,6 +86,7 @@ class StringHolder(ObjectHolder[str]): def endswith_method(self, args: T.Tuple[str], kwargs: TYPE_kwargs) -> bool: return self.held_object.endswith(args[0]) + @noArgsFlattening @noKwargs @typed_pos_args('str.format', varargs=object) def format_method(self, args: T.Tuple[T.List[object]], kwargs: TYPE_kwargs) -> str: diff --git a/test cases/common/35 string operations/meson.build b/test cases/common/35 string operations/meson.build index b86e13a..2ba70b6 100644 --- a/test cases/common/35 string operations/meson.build +++ b/test cases/common/35 string operations/meson.build @@ -60,6 +60,7 @@ assert(false.to_string() == 'false', 'bool string conversion failed') assert(true.to_string('yes', 'no') == 'yes', 'bool string conversion with args failed') assert(false.to_string('yes', 'no') == 'no', 'bool string conversion with args failed') assert('@0@'.format(true) == 'true', 'bool string formatting failed') +assert('@0@'.format(['one', 'two']) == '[\'one\', \'two\']', 'list string formatting failed') assert(' '.join(['a', 'b', 'c']) == 'a b c', 'join() array broken') assert(''.join(['a', 'b', 'c']) == 'abc', 'empty join() broken') |