cgen: fix optional_void error; handle `?` return type
parent
d73bedc1fb
commit
8500c8885c
|
@ -323,8 +323,9 @@ fn (g &Gen) base_type(t table.Type) string {
|
|||
fn (mut g Gen) register_optional(t table.Type, styp string) {
|
||||
// g.typedefs2.writeln('typedef Option $x;')
|
||||
no_ptr := styp.replace('*', '_ptr')
|
||||
typ := if styp == 'void' { 'void*' } else { styp }
|
||||
g.hotcode_definitions.writeln('typedef struct {
|
||||
$styp data;
|
||||
$typ data;
|
||||
string error;
|
||||
int ecode;
|
||||
bool ok;
|
||||
|
|
|
@ -123,7 +123,10 @@ pub fn (mut p Parser) parse_type() table.Type {
|
|||
p.next()
|
||||
p.check(.dot)
|
||||
}
|
||||
mut typ := p.parse_any_type(is_c, is_js, nr_muls > 0)
|
||||
mut typ := table.void_type
|
||||
if p.tok.kind != .lcbr {
|
||||
typ = p.parse_any_type(is_c, is_js, nr_muls > 0)
|
||||
}
|
||||
if is_optional {
|
||||
typ = typ.set_flag(.optional)
|
||||
}
|
||||
|
|
|
@ -207,3 +207,28 @@ fn test_multi_return_opt() {
|
|||
}
|
||||
}
|
||||
*/
|
||||
|
||||
fn foo() ?void {
|
||||
return error('something')
|
||||
}
|
||||
|
||||
fn test_optional_void() {
|
||||
foo() or {
|
||||
println(err)
|
||||
assert err == 'something'
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn bar() ? {
|
||||
return error('bar error')
|
||||
}
|
||||
|
||||
fn test_optional_void_only_question() {
|
||||
bar() or {
|
||||
println(err)
|
||||
assert err == 'bar error'
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue