aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/interpreterbase.py8
-rw-r--r--test cases/common/238 fstrings/meson.build6
2 files changed, 8 insertions, 6 deletions
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index d486b89..93cd1c6 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -934,11 +934,15 @@ The result of this is undefined and will become a hard error in a future Meson r
def replace(match: T.Match[str]) -> str:
var = str(match.group(1))
try:
- return str(self.variables[var])
+ val = self.variables[var]
+ if not isinstance(val, (str, int, float, bool)):
+ raise mesonlib.MesonException(f'Identifier {var} does not name a formattable variable.')
+
+ return str(val)
except KeyError:
raise mesonlib.MesonException(f'Identifier "{var}" does not name a variable.')
- return re.sub(r'{([_a-zA-Z][_0-9a-zA-Z]*)}', replace, node.value)
+ return re.sub(r'@([_a-zA-Z][_0-9a-zA-Z]*)@', replace, node.value)
def evaluate_foreach(self, node: mparser.ForeachClauseNode) -> None:
assert(isinstance(node, mparser.ForeachClauseNode))
diff --git a/test cases/common/238 fstrings/meson.build b/test cases/common/238 fstrings/meson.build
index ffee053..2db2649 100644
--- a/test cases/common/238 fstrings/meson.build
+++ b/test cases/common/238 fstrings/meson.build
@@ -2,8 +2,6 @@ project('meson-test', 'c')
n = 10
m = 'bar'
-s = f'test {n} string ({n}): {m}'
+s = f'test @n@ string (@@n@@): @m@'
-if s != 'test 10 string (10): bar'
- error('Incorrect string formatting')
-endif
+assert(s == 'test 10 string (@10@): bar', 'Incorrect string formatting')