Skip to content

Commit 3c20e48

Browse files
authored
Assert bug fix
1 parent c1f276c commit 3c20e48

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

compiler/compiler.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,17 +2141,30 @@ int compile_expr(struct compiler* compiler, Node* expr){
21412141

21422142
add_instruction(compiler, compiler->instructions,LOAD_ATTR, idx, GET_ANNO_N(names->at(i)));
21432143

2144+
2145+
object* stargs=new_tuple();
2146+
object* stkwargs=new_tuple();
21442147
object* kwargs=new_tuple();
21452148

2149+
int i_=0;
2150+
size_t argsize=CALL(expr->node)->args->size();
2151+
21462152
//Args (iterate backwards)
2147-
for (auto it = (*DOTCALL(expr->node)->args).rbegin(); it != (*DOTCALL(expr->node)->args).rend(); ++it){
2153+
for (auto it = (*CALL(expr->node)->args).rbegin(); it != (*CALL(expr->node)->args).rend(); ++it){
21482154
int cmpexpr=compile_expr_keep(compiler, *it);
21492155
if (cmpexpr==COMPILER_ERROR){
21502156
return cmpexpr;
21512157
}
2158+
if (find(CALL(expr->node)->stargs->begin(), CALL(expr->node)->stargs->end(), i_)!=CALL(expr->node)->stargs->end()){
2159+
tuple_append_noinc(stargs, new_int_fromint(i_));
2160+
}
2161+
if (find(CALL(expr->node)->stkwargs->begin(), CALL(expr->node)->stkwargs->end(), i_+argsize-1)!=CALL(expr->node)->stkwargs->end()){
2162+
tuple_append_noinc(stkwargs, new_int_fromint(i_+argsize-1));
2163+
}
2164+
i_++;
21522165
}
21532166
//Kwargs (iterate backwards)
2154-
for (auto it = (*DOTCALL(expr->node)->kwargs).rbegin(); it != (*DOTCALL(expr->node)->kwargs).rend(); ++it){
2167+
for (auto it = (*CALL(expr->node)->kwargs).rbegin(); it != (*CALL(expr->node)->kwargs).rend(); ++it){
21552168
tuple_append_noinc(kwargs, str_new_fromstr(*IDENTI(ASSIGN((*it)->node)->name->node)->name));
21562169
int cmpexpr=compile_expr_keep(compiler, ASSIGN((*it)->node)->right);
21572170
if (cmpexpr==COMPILER_ERROR){
@@ -2174,15 +2187,6 @@ int compile_expr(struct compiler* compiler, Node* expr){
21742187
add_instruction(compiler, compiler->instructions,LOAD_CONST,idx, GET_ANNO_N(expr));
21752188
}
21762189

2177-
object* stargs=new_tuple();
2178-
for (int i: *DOTCALL(expr->node)->stargs){
2179-
tuple_append_noinc(stargs, new_int_fromint(i));
2180-
}
2181-
object* stkwargs=new_tuple();
2182-
for (int i: *DOTCALL(expr->node)->stkwargs){
2183-
tuple_append_noinc(stkwargs, new_int_fromint(i));
2184-
}
2185-
21862190
if (CAST_TUPLE(stargs)->size != 0 || CAST_TUPLE(stkwargs)->size != 0){
21872191
if (!object_find_bool(compiler->consts,stargs)){
21882192
//Create object
@@ -3932,7 +3936,7 @@ int compile_expr(struct compiler* compiler, Node* expr){
39323936

39333937
case N_ASSERT: {
39343938
compile_expr_keep(compiler, ASSERT(expr->node)->expr);
3935-
add_instruction(compiler, compiler->instructions,POP_JMP_TOS_TRUE, 2, GET_ANNO_N(expr));
3939+
add_instruction(compiler, compiler->instructions,POP_JMP_TOS_TRUE, (compiler->instructions->count*2)+2, GET_ANNO_N(expr));
39363940
add_instruction(compiler, compiler->instructions,RAISE_ASSERTIONERR, 0, GET_ANNO_N(expr));
39373941
break;
39383942
}

0 commit comments

Comments
 (0)