Fix crash in meson format
There was a case where a trailing comma was missing a whitespaces attribute
Fixes #13242
diff --git a/mesonbuild/mformat.py b/mesonbuild/mformat.py
index 68c9a1f..5e37019 100644
--- a/mesonbuild/mformat.py
+++ b/mesonbuild/mformat.py
@@ -626,6 +626,7 @@
if need_comma and not has_trailing_comma:
comma = mparser.SymbolNode(mparser.Token('comma', node.filename, 0, 0, 0, (0, 0), ','))
comma.condition_level = node.condition_level
+ comma.whitespaces = mparser.WhitespaceNode(mparser.Token('whitespace', node.filename, 0, 0, 0, (0, 0), ''))
node.commas.append(comma)
elif has_trailing_comma and not need_comma:
node.commas.pop(-1)
diff --git a/test cases/format/1 default/gh13242.meson b/test cases/format/1 default/gh13242.meson
new file mode 100644
index 0000000..b9122ec
--- /dev/null
+++ b/test cases/format/1 default/gh13242.meson
@@ -0,0 +1,18 @@
+# Minimized meson.build
+test(
+ args: [
+ shared_library(
+ f'tstlib-@name@',
+ build_by_default: false,
+ override_options: opt,
+ ),
+ ],
+)
+
+test(
+ should_fail: (settings.get('x', false) and not settings['y'] and dep.version(
+
+ ).version_compare(
+ '>=1.2.3',
+ )),
+)
diff --git a/test cases/format/1 default/meson.build b/test cases/format/1 default/meson.build
index 5b5b115..35e5b96 100644
--- a/test cases/format/1 default/meson.build
+++ b/test cases/format/1 default/meson.build
@@ -7,6 +7,7 @@
'self': files('meson.build'),
'comments': files('crazy_comments.meson'),
'indentation': files('indentation.meson'),
+ 'gh13242': files('gh13242.meson'),
}
foreach name, f : meson_files