v.gen.c: fix cgen regression after f457b94
(prevented vinix builds), add tests
parent
6438099644
commit
db5e0f2117
|
@ -1309,9 +1309,17 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
|
|||
|| deref_sym.kind in [.sum_type, .interface_]) && lang != .c {
|
||||
if arg.expr.is_lvalue() {
|
||||
g.write('(voidptr)&/*qq*/')
|
||||
} else {
|
||||
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(expected_deref_type)}/*qq*/, ')
|
||||
g.write('ADDR(${g.typ(atype)}/*qq*/, ')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
Loading…
Reference in New Issue