cgen: fix unsafe return error (#14233)

Daniel Däschle 2022-04-30 16:31:28 +02:00 committed by Jef Roosens
parent 924e2e65fe
commit d75469965e
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -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' }
}