Skip to content

Commit

Permalink
Fix call dyn for object member.
Browse files Browse the repository at this point in the history
  • Loading branch information
fubark committed Jun 7, 2024
1 parent 420f4f0 commit 95cd639
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5395,10 +5395,15 @@ pub const ChunkExt = struct {
const rightName = c.ast.nodeString(callee.right);
const leftTypeSym = c.sema.getTypeSym(leftRes.type.id);
const rightSym = try c.mustFindSym(leftTypeSym, rightName, callee.right);
const func_sym = try requireFuncSym(c, rightSym, callee.right);

return c.semaCallFuncSymRec(preIdx, func_sym, callee.left, leftRes,
node.args, expr.getRetCstr(), expr.node);
if (rightSym.type == .func) {
return c.semaCallFuncSymRec(preIdx, rightSym.cast(.func), callee.left, leftRes,
node.args, expr.getRetCstr(), expr.node);
} else {
const callee_v = try c.semaExpr(node.callee, .{});
const args = try c.semaPushDynCallArgs(node.args);
return c.semaCallValue(preIdx, callee_v.irIdx, node.args.len, args);
}
}
}
} else if (node.callee.type() == .ident) {
Expand Down
2 changes: 2 additions & 0 deletions test/behavior_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ if (!aot) {
run.case("functions/call_closure.cy");
run.case("functions/call_closure_param_panic.cy");
}

run.case("functions/call_dyn_object_member.cy");
run.case("functions/call_excess_args_error.cy");
run.case("functions/call_excess_args_overloaded_error.cy");
if (!aot) {
Expand Down
12 changes: 12 additions & 0 deletions test/functions/call_dyn_object_member.cy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use test

type Foo:
member dyn

func foo():
return self.member()

var f = Foo{member=() => 3}
test.eq(f.foo(), 3)

--cytest: pass

0 comments on commit 95cd639

Please sign in to comment.