Skip to content

Commit

Permalink
fixed #236: correctly handling class type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kray-G committed Mar 31, 2021
1 parent 63775b3 commit 8f6a55d
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/ast_analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,21 +326,16 @@ static void reset_base_symbol(kx_context_t *ctx, kxana_context_t *actx, kx_objec

static void append_typename(kx_object_t *node)
{
const char *type = NULL;
kx_object_t *base = node;
if (!node->lhs || node->lhs->type != KXOP_VAR) {
return;
}
const char *varname = node->lhs->value.s;
if (strcmp(varname, "this") == 0) {
return;
if (node->rhs) {
node->lhs->typename = node->rhs->typename;
node->lhs->var_type = node->rhs->var_type;
}
}

node = node->rhs;
if (!node || node->type != KXOP_CALL) {
return;
}
node = node->lhs;
static void append_classtype(kx_object_t *callnode)
{
const char *type = NULL;
kx_object_t *node = callnode->lhs;
if (!node || node->type != KXOP_IDX) {
return;
}
Expand All @@ -355,8 +350,8 @@ static void append_typename(kx_object_t *node)
}
}
if (type) {
node->lhs->typename = type;
base->lhs->typename = type;
callnode->typename = type;
node->typename = type;
}
}

Expand Down Expand Up @@ -1311,6 +1306,7 @@ LOOP_HEAD:;
kx_yyerror_line("Can not call a native function without returning type", node->file, node->line);
}
}
append_classtype(node);
break;
}

Expand Down Expand Up @@ -1559,7 +1555,13 @@ LOOP_HEAD:;
} else {
make_cast_to(actx->func->ret_type, node);
}
if (actx->func->ret_type != node->lhs->var_type) {
if (actx->func->ret_typename) {
if (!node->lhs->typename) {
kx_yyerror_line_fmt("Expect return type (%s) but (%s)", node->file, node->line, actx->func->ret_typename, get_typename(node->lhs->var_type));
} else if (strcmp(actx->func->ret_typename, node->lhs->typename) != 0) {
kx_yyerror_line_fmt("Expect return type (%s) but (%s)", node->file, node->line, actx->func->ret_typename, node->lhs->typename);
}
} else if (actx->func->ret_type != node->lhs->var_type) {
kx_yyerror_line_fmt("Expect return type (%s) but (%s)", node->file, node->line, get_typename(actx->func->ret_type), get_typename(node->lhs->var_type));
}
}
Expand Down

0 comments on commit 8f6a55d

Please sign in to comment.