cgen: fix codegen for comptime multiline attr (fix #23964) (#24087)

This commit is contained in:
Felipe Pena 2025-03-30 10:11:00 -03:00 committed by GitHub
parent a3180e5747
commit 94a91c263e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -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('}')

View File

@ -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'
}
}