Skip to content

Commit

Permalink
Print it properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Jan 5, 2025
1 parent f0ea623 commit 670ddbe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion self_hosted/ast.jou
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,13 @@ class AstSignature:
for i = 0; i < self->nargs; i++:
if i != 0:
printf(", ")
if strcmp(self->args[i].name, "self") == 0:

if (
strcmp(self->args[i].name, "self") == 0
and self->args[i].type.kind == AstTypeKind::Named
and self->args[i].type.name[0] == '\0'
):
# self with implicitly given type
printf("self")
else:
self->args[i].print_with_tree_printer(NULL)
Expand Down
5 changes: 3 additions & 2 deletions src/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ static void print_ast_function_signature(const AstSignature *sig)
printf("%s(", sig->name);
for (const AstNameTypeValue *ntv = sig->args.ptr; ntv < End(sig->args); ntv++) {
if (ntv > sig->args.ptr) printf(", ");
if (!strcmp(ntv->name, "self"))
if (!strcmp(ntv->name, "self") && ntv->type.kind == AST_TYPE_NAMED && ntv->type.data.name[0] == '\0') {
// self with implicitly given type
printf("self");
else{
} else {
printf("%s: ", ntv->name);
print_ast_type(&ntv->type);
}
Expand Down

0 comments on commit 670ddbe

Please sign in to comment.