1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.gen.c: fix cgen regression after f457b94 (prevented vinix builds), add tests

This commit is contained in:
Delyan Angelov 2021-07-25 23:23:16 +03:00
parent 6438099644
commit db5e0f2117
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 42 additions and 2 deletions

View File

@ -1310,8 +1310,16 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
if arg.expr.is_lvalue() {
g.write('(voidptr)&/*qq*/')
} else {
needs_closing = true
g.write('ADDR(${g.typ(expected_deref_type)}/*qq*/, ')
mut atype := expected_deref_type
if atype.has_flag(.generic) {
atype = g.unwrap_generic(atype)
}
if atype.has_flag(.generic) {
g.write('(voidptr)&/*qq*/')
} else {
needs_closing = true
g.write('ADDR(${g.typ(atype)}/*qq*/, ')
}
}
}
}

View File

@ -0,0 +1,32 @@
const zzz = &Local{}
struct Local {
aborted bool
}
pub fn current() &Local {
return zzz
}
pub fn store<T>(var &T, value T) {
eprintln('store ${voidptr(var)} <- $value')
unsafe {
*var = value
}
}
fn test_generic_over_a_local_boolean_address() {
eprintln('-'.repeat(40))
mut mybool := false
println(mybool)
store(mybool, true)
println(mybool)
eprintln('-'.repeat(40))
}
fn test_generic_over_a_const_returned_by_a_fn() {
println(current().aborted)
store(current().aborted, true)
println(current().aborted)
eprintln('-'.repeat(40))
}