From: NeilBrown Date: Mon, 15 Nov 2021 21:14:27 +0000 (+1100) Subject: oceani: mark structure return from functions as not supported. X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=4edaeb7f2f51bb7486b11783b65ffcce2d2244f7 oceani: mark structure return from functions as not supported. Functions can currently only return types that support ->dup. So disallow anything that doesn't. Signed-off-by: NeilBrown --- diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc index 4dceab4..7a40817 100644 --- a/csrc/oceani-tests.mdc +++ b/csrc/oceani-tests.mdc @@ -999,7 +999,17 @@ Test for type errors with functions func test5(a:number):string print a + struct foo + a: number + b:string = "hello" + + func test6(a:number):foo + b:foo + b.a = a + use b + ###### output: func_err_args + .tmp.code:34:5: error: function cannot return value of type foo .tmp.code:28:14: error: expected string, found none .tmp.code:25:8: error: expected string, found number .tmp.code:15:14: error: insufficient arguments to function. diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index 96fe6c6..12beeb2 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -4845,6 +4845,11 @@ is a bit more interesting at this level. v->type->function.return_type, 0); if (!ok) all_ok = 0; + if (!v->type->function.return_type->dup) { + type_err(c, "error: function cannot return value of type %1", + v->where_decl, v->type->function.return_type, 0, NULL); + } + v->type->function.local_size = scope_finalize(c); } return all_ok;