From 94a91c263e37161f53b0860b1123e5dd64dbcb0c Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 30 Mar 2025 10:11:00 -0300 Subject: [PATCH] cgen: fix codegen for comptime multiline attr (fix #23964) (#24087) --- vlib/v/gen/c/comptime.v | 3 ++- vlib/v/tests/comptime/comptime_multiline_attr_test.v | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/comptime/comptime_multiline_attr_test.v diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index 040b560e8..f816bc9f3 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -987,7 +987,8 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) { g.writeln('/* attribute ${i} */ {') g.writeln('\t${node.val_var}.name = _SLIT("${attr.name}");') g.writeln('\t${node.val_var}.has_arg = ${attr.has_arg};') - g.writeln('\t${node.val_var}.arg = _SLIT("${attr.arg}");') + g.writeln('\t${node.val_var}.arg = _SLIT("${util.smart_quote(attr.arg, + false)}");') g.writeln('\t${node.val_var}.kind = AttributeKind__${attr.kind};') g.stmts(node.stmts) g.writeln('}') diff --git a/vlib/v/tests/comptime/comptime_multiline_attr_test.v b/vlib/v/tests/comptime/comptime_multiline_attr_test.v new file mode 100644 index 000000000..8a7c380d9 --- /dev/null +++ b/vlib/v/tests/comptime/comptime_multiline_attr_test.v @@ -0,0 +1,11 @@ +module main + +@[footer: 'Hello +World'] +pub struct Config {} + +fn test_main() { + $for a in Config.attributes { + assert a.arg == 'Hello\nWorld' + } +} -- 2.39.5