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

pull/10968/head
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

@ -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 { || deref_sym.kind in [.sum_type, .interface_]) && lang != .c {
if arg.expr.is_lvalue() { if arg.expr.is_lvalue() {
g.write('(voidptr)&/*qq*/') 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 { } else {
needs_closing = true needs_closing = true
g.write('ADDR(${g.typ(expected_deref_type)}/*qq*/, ') 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))
}