Skip to content

Commit c05684e

Browse files
authored
v.reflection: fix codegen to work with quoted strings on attr value (fix #23046) (#23050)
1 parent 1da7965 commit c05684e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

vlib/v/gen/c/reflection.v

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ fn (g &Gen) gen_attrs_array(attrs []ast.Attr) string {
9595
}
9696
mut out := 'new_array_from_c_array(${attrs.len},${attrs.len},sizeof(string),'
9797
out += '_MOV((string[${attrs.len}]){'
98-
out += attrs.map(if it.has_arg { '_SLIT("${it.name}=${it.arg}")' } else { '_SLIT("${it.name}")' }).join(',')
98+
out += attrs.map(if it.has_arg {
99+
'_SLIT("${it.name}=${escape_quotes(it.arg)}")'
100+
} else {
101+
'_SLIT("${it.name}")'
102+
}).join(',')
99103
out += '}))'
100104
return out
101105
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import v.reflection as r
2+
3+
struct MyParams {
4+
p_fpga_ver string @[long: fp_ver; name: 'FPGA Version'; xdoc: 'String to use as simulated FPGA version in Version responses. Must be in the form "a.bb.cccc"']
5+
p_cm_ver string @[long: cm_ver; name: 'CM Version'; xdoc: 'String to use as simulated CM version in Version responses. Must be in the form "a.bb.cccc"']
6+
}
7+
8+
fn test_main() {
9+
a := MyParams{}
10+
t := r.type_of(a)
11+
if t.sym.info is r.Struct {
12+
assert t.sym.info.fields[0].attrs[2] == 'xdoc=String to use as simulated FPGA version in Version responses. Must be in the form "a.bb.cccc"'
13+
} else {
14+
assert false
15+
}
16+
}

0 commit comments

Comments
 (0)