cgen: fix unsafe return error (#14233)

master
Daniel Däschle 2022-04-30 16:31:28 +02:00 committed by GitHub
parent 0b54196962
commit ec92d467d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 { fn (mut g Gen) type_default(typ_ ast.Type) string {
typ := g.unwrap_generic(typ_) typ := g.unwrap_generic(typ_)
if typ.has_flag(.optional) { if typ.has_flag(.optional) || typ.has_flag(.result) {
return '{0}' return '{0}'
} }
// Always set pointers to 0 // Always set pointers to 0

View File

@ -63,3 +63,13 @@ fn util_error_propagation() ! {
fn test_return_on_error_propagation() { fn test_return_on_error_propagation() {
util_error_propagation() or { assert err.msg() == 'abc' } 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' }
}