Skip to content

Commit df8862f

Browse files
committed
fixed: piping into a method call
1 parent bbf1635 commit df8862f

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

compiler/src/symres.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,13 @@ static SymresStatus symres_if_expression(AstIfExpression* if_expr) {
485485
}
486486

487487
static SymresStatus symres_pipe(AstBinaryOp** pipe) {
488-
AstCall* call_node = (AstCall *) (*pipe)->right;
489-
if (call_node->kind != Ast_Kind_Call) {
488+
AstCall* base_call_node = (AstCall *) (*pipe)->right;
489+
AstCall* call_node = base_call_node;
490+
if (call_node->kind == Ast_Kind_Method_Call) {
491+
call_node = (AstCall *) ((AstBinaryOp *) call_node)->right;
492+
}
493+
494+
if (!call_node || call_node->kind != Ast_Kind_Call) {
490495
onyx_report_error((*pipe)->token->pos, Error_Critical, "Pipe operator expected call on right side.");
491496
return Symres_Error;
492497
}
@@ -504,10 +509,10 @@ static SymresStatus symres_pipe(AstBinaryOp** pipe) {
504509
call_node->args.values[0] = (AstTyped *) make_argument(context.ast_alloc, (*pipe)->left);
505510
}
506511

507-
call_node->next = (*pipe)->next;
508-
*pipe = (AstBinaryOp *) call_node;
512+
base_call_node->next = (*pipe)->next;
513+
*pipe = (AstBinaryOp *) base_call_node;
509514

510-
SYMRES(expression, (AstTyped **) &call_node);
515+
SYMRES(expression, (AstTyped **) pipe);
511516
return Symres_Success;
512517
}
513518

tests/pipe_into_method_call

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Test: 123

tests/pipe_into_method_call.onyx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use core {*}
2+
3+
Foo :: struct {
4+
name: str
5+
}
6+
7+
Foo.print :: (self: &#Self, y: str, x: i32) {
8+
printf("{}: {}\n", self.name, x)
9+
}
10+
11+
main :: () {
12+
f := Foo.{"Test"}
13+
14+
x := 123
15+
16+
x |> f->print("asdf", _)
17+
}

0 commit comments

Comments
 (0)