Skip to content

Commit 8388ea5

Browse files
committedFeb 16, 2025
Fix method call on a pointer
1 parent 6244c31 commit 8388ea5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed
 

‎src/AST/Expressions/MethodCallNode.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "kyoto/AST/Expressions/IdentifierNode.h"
1111
#include "kyoto/AST/Expressions/UnaryNode.h"
1212
#include "kyoto/KType.h"
13+
#include "kyoto/ModuleCompiler.h"
1314

1415
MethodCall::MethodCall(std::string instance_name, std::string name, std::vector<ExpressionNode*> args,
1516
ModuleCompiler& compiler)
@@ -27,8 +28,15 @@ std::string MethodCall::to_string() const
2728

2829
llvm::Value* MethodCall::gen()
2930
{
31+
auto instance_symbol = compiler.get_symbol(instance_name);
32+
if (!instance_symbol.has_value()) {
33+
throw std::runtime_error(fmt::format("MethodCall::gen: Symbol {} not found", instance_name));
34+
}
35+
3036
ExpressionNode* self = new IdentifierExpressionNode(instance_name, compiler);
31-
self = new UnaryNode(self, UnaryNode::UnaryOp::AddressOf, compiler);
37+
if (!instance_symbol.value().type->is_pointer_to_class()) {
38+
self = new UnaryNode(self, UnaryNode::UnaryOp::AddressOf, compiler);
39+
}
3240
insert_arg(self, 0);
3341
auto class_name = self->get_ktype()->get_class_name();
3442
set_name_prefix(class_name + "_");

0 commit comments

Comments
 (0)