cgen: fix unsafe return error (#14233)
parent
0b54196962
commit
ec92d467d1
|
@ -5181,7 +5181,7 @@ fn c_name(name_ string) string {
|
|||
|
||||
fn (mut g Gen) type_default(typ_ ast.Type) string {
|
||||
typ := g.unwrap_generic(typ_)
|
||||
if typ.has_flag(.optional) {
|
||||
if typ.has_flag(.optional) || typ.has_flag(.result) {
|
||||
return '{0}'
|
||||
}
|
||||
// Always set pointers to 0
|
||||
|
|
|
@ -63,3 +63,13 @@ fn util_error_propagation() ! {
|
|||
fn test_return_on_error_propagation() {
|
||||
util_error_propagation() or { assert err.msg() == 'abc' }
|
||||
}
|
||||
|
||||
fn unsafe_return_error() !int {
|
||||
unsafe {
|
||||
return error('abc')
|
||||
}
|
||||
}
|
||||
|
||||
fn test_unsafe_return_error() {
|
||||
unsafe_return_error() or { assert err.msg() == 'abc' }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue