You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When compile code for generic array of map[string]string, it will cause C compile fail
Reproduction Steps
g.v
modulemainfnencode_map[K,V](m map[K]V) {
println('${typeof(m).name}')
}
fnencode_array[T](arr []T) {
for element in arr {
$if T is $map {
encode_map(element)
}
}
}
fnmain() {
x:= [{'123':'456'},{'abc':'def'},]
encode_array(x)
}
just compile with v g.v
Expected Behavior
compile ok
Current Behavior
$ v g.v
================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/g.01JQKJSA0PTK3MQ144VG9AM1XC.tmp.c:1540: error: ',' expected (got "m")
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
builder error:
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .
Possible Solution
By run v g.v -showcc -keepc and check the generated C code, it is found that v compiler generate extra C code for the program:
Note that the compiler should not generate the main__encode_map_T_Map_string_string_string() function.
Or miss a declare for typedef map Map_Map_string_string_string;
Describe the bug
When compile code for generic array of map[string]string, it will cause C compile fail
Reproduction Steps
g.v
just compile with
v g.vExpected Behavior
compile ok
Current Behavior
Possible Solution
By run
v g.v -showcc -keepcand check the generated C code, it is found that v compiler generate extra C code for the program:Note that the compiler should not generate the
main__encode_map_T_Map_string_string_string()function.Or miss a declare for
typedef map Map_Map_string_string_string;Maybe a fix for the cgen can fix this.
Additional Information/Context
related C code:
V version
V 0.4.10 690f845.a3180e5
Environment details (OS name and version, etc.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.