aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-05-12 15:48:52 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-05-12 15:48:52 -0400
commitf6f89265b7eb73bd9a036133033e4fd654196b50 (patch)
tree602f3a4c42330eb0a2f731b0aa7f951684bd2ace
parent4dbe046866a6280cf304c7e0ec6471d872bc8e27 (diff)
Guard against calling interfaces with values
-rw-r--r--compile.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/compile.c b/compile.c
index 782fc3fe..7595a6ec 100644
--- a/compile.c
+++ b/compile.c
@@ -1662,10 +1662,11 @@ CORD compile(env_t *env, ast_t *ast)
arg_t *type_args = Match(field_t, FunctionType)->args;
CORD args = compile_arguments(env, ast, type_args->next, methodcall->args);
- bool is_ptr = Match(field_t, FunctionType)->args->type->tag == PointerType;
+ if (Match(field_t, FunctionType)->args->type->tag != PointerType)
+ code_err(ast, "Interface methods that take value types can't be called");
return CORD_all("({ ", compile_type(env, self_value_t), " $self = ",
compile_to_pointer_depth(env, methodcall->self, 0, false), "; ",
- "$self.", methodcall->name, "(", is_ptr ? CORD_EMPTY : "*", "(", compile_type(env, self_value_t), "*)$self.$obj",
+ "$self.", methodcall->name, "($self.$obj",
args == CORD_EMPTY ? CORD_EMPTY : ", ", args, "); })");
}
}