Skip to content

Commit

Permalink
Support namespace calls for different types.
Browse files Browse the repository at this point in the history
  • Loading branch information
fubark committed Aug 1, 2024
1 parent d183885 commit 42b6e87
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3116,24 +3116,14 @@ fn callSym(c: *cy.Chunk, sym: *Sym, symNode: *ast.Node, args: []*ast.Node, ret_c
const funcSym = sym.cast(.func);
return c.semaCallFuncSym(funcSym, args, ret_cstr, symNode);
},
.bool_t => {
return callNamespaceSym(c, sym, symNode, args, ret_cstr, node);
},
.int_t => {
return callNamespaceSym(c, sym, symNode, args, ret_cstr, node);
},
.float_t => {
return callNamespaceSym(c, sym, symNode, args, ret_cstr, node);
},
.hostobj_t => {
return callNamespaceSym(c, sym, symNode, args, ret_cstr, node);
},
.struct_t => {
return callNamespaceSym(c, sym, symNode, args, ret_cstr, node);
},
.object_t => {
return callNamespaceSym(c, sym, symNode, args, ret_cstr, node);
},
.trait_t,
.enum_t,
.bool_t,
.int_t,
.float_t,
.hostobj_t,
.struct_t,
.object_t,
.template => {
return callNamespaceSym(c, sym, symNode, args, ret_cstr, node);
},
Expand Down
1 change: 1 addition & 0 deletions test/behavior_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ if (!aot) {
run.case("functions/lambda_incompat_arg_panic.cy");
run.case("functions/let_call_recursive.cy");
run.case("functions/let_func.cy");
run.case("functions/namespace_call.cy");
run.case("functions/object_funcs.cy");
run.case("functions/overload.cy");
run.case("functions/read_capture_local_error.cy");
Expand Down
43 changes: 43 additions & 0 deletions test/functions/namespace_call.cy
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use test

type FooS struct:
a int

func FooS.$call(i int):
return i

test.eq(FooS(10), 10)

type FooCS cstruct:
a int

func FooCS.$call(i int):
return i

test.eq(FooCS(10), 10)

type FooO:
a int

func FooO.$call(i int):
return i

test.eq(FooO(10), 10)

type FooE enum:
case a

func FooE.$call(i int):
return i

test.eq(FooE(10), 10)

type FooT trait:
func foo(self) void

func FooT.$call(i int):
return i

test.eq(FooT(10), 10)

--cytest: pass

0 comments on commit 42b6e87

Please sign in to comment.