v
v copied to clipboard
String attributes with quotes inside result in C error
V Doctor:
OS: linux, Ubuntu 20.04.4 LTS (WSL 2)
Processor: 12 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i5-11400H @ 2.70GHz
CC version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
getwd: /home/apocryphon/tests/v
vmodules: /home/apocryphon/.vmodules
vroot: /home/apocryphon/packages/v
vexe: /home/apocryphon/packages/v/v
vexe mtime: 2022-07-23 19:22:13
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.0 d6de533.d8b0df1
Git version: git version 2.25.1
Git vroot status: weekly.2022.29-51-gd8b0df1a
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 827f7452
What did you do?
struct Dummy {}
['option: "1"'] // <--------
fn (d Dummy) sample_method() {
// ...
}
fn main() {
$for method in Dummy.methods {
println(method)
}
}
What did you expect to see?
No errors from the compiler, with the following output in the console:
FunctionData{
name: 'sample_method'
attrs: ['option: "1"']
args: []
return_type: 1
typ: 0
}
What did you see instead?
v -cg -prod bug_2.v
outputs:
/tmp/v_1000/bug_2.13727280715846017.tmp.c: In function ‘reflection__methods_of_type_T_main__Dummy’:
/tmp/v_1000/bug_2.13727280715846017.tmp.c:12184:97: error: expected ‘)’ before numeric constant
12184 | method.attrs = new_array_from_c_array(1, 1, sizeof(string), _MOV((string[1]){_SLIT("option: "1"")}));
| ^
/tmp/v_1000/bug_2.13727280715846017.tmp.c:169:46: note: in definition of macro ‘_SLIT’
169 | #define _SLIT(s) ((string){.str=(byteptr)("" s), .len=(sizeof(s)-1), .is_lit=1})
| ^
/tmp/v_1000/bug_2.13727280715846017.tmp.c:169:42: note: to match this ‘(’
169 | #define _SLIT(s) ((string){.str=(byteptr)("" s), .len=(sizeof(s)-1), .is_lit=1})
| ^
/tmp/v_1000/bug_2.13727280715846017.tmp.c:12184:81: note: in expansion of macro ‘_SLIT’
12184 | method.attrs = new_array_from_c_array(1, 1, sizeof(string), _MOV((string[1]){_SLIT("option: "1"")}));
| ^~~~~
/tmp/v_1000/bug_2.13727280715846017.tmp.c:12184:97: error: expected ‘)’ before numeric constant
12184 | method.attrs = new_array_from_c_array(1, 1, sizeof(string), _MOV((string[1]){_SLIT("option: "1"")}));
| ^
/tmp/v_1000/bug_2.13727280715846017.tmp.c:169:63: note: in definition of macro ‘_SLIT’
169 | #define _SLIT(s) ((string){.str=(byteptr)("" s), .len=(sizeof(s)-1), .is_lit=1})
| ^
/tmp/v_1000/bug_2.13727280715846017.tmp.c:169:62: note: to match this ‘(’
169 | #define _SLIT(s) ((string){.str=(byteptr)("" s), .len=(sizeof(s)-1), .is_lit=1})
| ^
/tmp/v_1000/bug_2.13727280715846017.tmp.c:12184:81: note: in expansion of macro ‘_SLIT’
12184 | method.attrs = new_array_from_c_array(1, 1, sizeof(string), _MOV((string[1]){_SLIT("option: "1"")}));
| ^~~~~
builder error:
==================
C error. This should never happen.
This is a compiler bug, please report it using `v bug file.v`.
https://github.com/vlang/v/issues/new/choose
You can also use #help on Discord: https://discord.gg/vlang
vfmt
modifies the code resulting in the same error shown above.
// vfmt output:
struct Dummy {}
['option: '1'']
fn (d Dummy) sample_method() {
// ...
}
fn main() {
$for methods in Dummy.methods {
println(methods)
}
}
Imo that shouldn't compile even without C error