Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add error for __init__ method #421

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions self_hosted/parser.jou
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,8 @@ class Parser:
self->tokens++

signature = self->parse_function_or_method_signature(is_method)
if strcmp(signature.name, "__init__") == 0 and is_method:
fail(self->tokens->location, "Jou does not have a special __init__ method like Python")
if signature.takes_varargs:
fail(self->tokens->location, "functions with variadic arguments cannot be defined yet")

Expand Down
3 changes: 3 additions & 0 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,9 @@ static AstFunction parse_funcdef(ParserState *ps, bool is_method)

struct AstFunction funcdef = {0};
funcdef.signature = parse_function_signature(ps, is_method);
if (!strcmp(funcdef.signature.name, "__init__") && is_method) {
fail_with_error(ps->tokens->location, "Jou does not have a special __init__ method like Python");
}
if (funcdef.signature.takes_varargs) {
// TODO: support "def foo(x: str, ...)" in some way
fail_with_error(ps->tokens->location, "functions with variadic arguments cannot be defined yet");
Expand Down
3 changes: 3 additions & 0 deletions tests/other_errors/python_init_method.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Foo:
Akuli marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self) -> void: # Error: Jou does not have a special __init__ method like Python
pass