Skip to content

Commit

Permalink
Add error message for foo().bar() (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli authored Dec 3, 2023
1 parent 334ed80 commit 2c7f2f8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions self_hosted/typecheck.jou
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,12 @@ class Stage3TypeChecker:
)
fail(call->location, message)

if call->method_call_self != NULL and not call->uses_arrow_operator:
snprintf(
message, sizeof message,
"cannot take address of %%s, needed for calling the %s() method", call->name)
ensure_can_take_address(call->method_call_self, message)

signature_string = signature->to_string(False, False)

expected = signature->nargs
Expand Down
8 changes: 8 additions & 0 deletions src/typecheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,14 @@ static ExpressionTypes *typecheck_expression(FileTypes *ft, const AstExpression
case AST_EXPR_CALL_METHOD:
temptype = typecheck_expression_not_void(ft, expr->data.methodcall.obj)->type;
result = typecheck_function_or_method_call(ft, &expr->data.methodcall.call, temptype, expr->location);

char tmp[500];
snprintf(
tmp, sizeof tmp,
"cannot take address of %%s, needed for calling the %s() method",
expr->data.methodcall.call.calledname);
ensure_can_take_address(expr->data.methodcall.obj, tmp);

if (!result)
return NULL;
break;
Expand Down
11 changes: 11 additions & 0 deletions tests/other_errors/func_then_method.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "stdlib/io.jou"

class Foo:
def do_stuff(self) -> void:
printf("Doing stuff!\n")

def make_foo() -> Foo:
return Foo{}

def bar() -> void:
make_foo().do_stuff() # Error: cannot take address of a function call, needed for calling the do_stuff() method

0 comments on commit 2c7f2f8

Please sign in to comment.