Skip to content

Commit

Permalink
check that global var type and its init value are the same (#1032)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrDet authored Jul 2, 2024
1 parent 5597a00 commit 3348823
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions compiler/code-gen/files/global-vars-reset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "compiler/code-gen/namespace.h"
#include "compiler/code-gen/vertex-compiler.h"
#include "compiler/data/src-file.h"
#include "compiler/inferring/public.h"
#include "compiler/inferring/type-data.h"
#include "compiler/kphp_assert.h"

GlobalVarsReset::GlobalVarsReset(const GlobalsBatchedMem &all_globals_in_mem)
: all_globals_in_mem(all_globals_in_mem) {}
Expand Down Expand Up @@ -41,6 +44,17 @@ void GlobalVarsReset::compile_globals_reset_part(CodeGenerator &W, const Globals
W << "// " << var->as_human_readable() << NL;
W << "hard_reset_var(" << GlobalVarInPhpGlobals(var);
if (var->init_val) {
// TODO: fix unstable type inferring
const TypeData *global_var_type = tinf::get_type(var);
const TypeData *init_val_type = tinf::get_type(var->init_val);
// a -> b <=> !a || b
kphp_error(!(global_var_type->get_real_ptype() == tp_array &&
init_val_type->get_real_ptype() == tp_array &&
init_val_type->lookup_at_any_key()->get_real_ptype() != tp_any)
|| are_equal_types(global_var_type, init_val_type),
fmt_format("Types of global variable and its init value differ: {} and {}.\n"
"Probably because of unstable type inferring, try rerun compilation",
global_var_type->as_human_readable(), init_val_type->as_human_readable()));
W << ", " << var->init_val;
}
W << ");" << NL;
Expand Down

0 comments on commit 3348823

Please sign in to comment.