]> ocean-lang.org Git - ocean/commitdiff
oceani: mark structure return from functions as not supported.
authorNeilBrown <neil@brown.name>
Mon, 15 Nov 2021 21:14:27 +0000 (08:14 +1100)
committerNeilBrown <neil@brown.name>
Mon, 15 Nov 2021 21:14:27 +0000 (08:14 +1100)
Functions can currently only return types that support ->dup.
So disallow anything that doesn't.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani-tests.mdc
csrc/oceani.mdc

index 4dceab407eee8c163f4a3e69fedca3b8ccf3afe6..7a408179378b67a59b15062e2ed0946eb417575f 100644 (file)
@@ -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.
index 96fe6c6d6922d82c89de66d37ce0375667a02f04..12beeb2c71952315a6373ec17407c15a1dcf6738 100644 (file)
@@ -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;