v
v copied to clipboard
Type alias cannot be a reference
V version: 0.2.2 OS: Linux
In this example I have two types that are equal:
-
&char
-
ALcharptr
When translated into C, both types (although equal) will be passed to char_vstring
differently:
-
char_vstring(s)
-
char_vstring(&s)
Full exampled here(zip).
V snippet
type ALcharptr = &char
fn C.return_text_one() ALcharptr
fn C.return_text_two() &char
fn main() {
println('type &char\talias ALcharptr\t:\t${get_one()}')
println('type &char\talias none\t:\t${get_two()}')
}
fn get_one() string {
s := C.return_text_one()
return unsafe { cstring_to_vstring(s) }
}
fn get_two() string {
s := C.return_text_two()
return unsafe { cstring_to_vstring(s) }
}
C snippet
void main__main(void) {
println(_STR("type &char\talias ALcharptr\t:\t%.*s", 1, main__get_one()));
println(_STR("type &char\talias none\t:\t%.*s", 1, main__get_two()));
}
string main__get_one(void) {
main__ALcharptr s = return_text_one();
string _t101 = char_vstring(&s); // <- Nein!
return _t101;
}
string main__get_two(void) {
char* s = return_text_two();
string _t102 = char_vstring(s);
return _t102;
}
Output
type &char alias ALcharptr : �lf
type &char alias none : text
Still an issue.
Cgen error on latest v:
PS D:\Games\Proekti\V\interactions> type test2.v
type ALcharptr = &char
fn C.return_text_one() ALcharptr
fn C.return_text_two() &char
fn main() {
println('type &char\talias ALcharptr\t:\t${get_one()}')
println('type &char\talias none\t:\t${get_two()}')
}
fn get_one() string {
s := C.return_text_one()
return unsafe { cstring_to_vstring(s) }
}
fn get_two() string {
s := C.return_text_two()
return unsafe { cstring_to_vstring(s) }
}
PS D:\Games\Proekti\V\interactions> v version
V 0.4.4 2a68e2b
PS D:\Games\Proekti\V\interactions> v run test2.v
==================
C:/Users/mclr/AppData/Local/Temp/v_0/test2.01HN390CQQ1AJEKT8Z3C0PW484.tmp.c:13009: warning: cast between pointer and integer of different size
tcc: error: undefined symbol 'return_text_one'
tcc: error: undefined symbol 'return_text_two'
...
==================
(Use `v -cg` to print the entire error message)
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