Skip to content

Commit dae7f50

Browse files
advikkabraczgdp1807
authored andcommitted
Initialize empty value to dictionaries without type given
1 parent fbbdbdd commit dae7f50

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,6 +2568,15 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
25682568
ASR::Variable_t* v_variable = ASR::down_cast<ASR::Variable_t>(v_sym);
25692569
std::string var_name = v_variable->m_name;
25702570
ASR::ttype_t* type = v_variable->m_type;
2571+
if (!init_expr && ASR::is_a<ASR::Dict_t>(*type)) {
2572+
ASR::ttype_t *key_type = ASR::down_cast<ASR::Dict_t>(type)->m_key_type;
2573+
ASR::ttype_t *value_type = ASR::down_cast<ASR::Dict_t>(type)->m_value_type;
2574+
ASR::ttype_t *dict_type = ASRUtils::TYPE(ASR::make_Dict_t(al, loc,
2575+
key_type, value_type));
2576+
init_expr = ASRUtils::EXPR(ASR::make_DictConstant_t(al, loc,
2577+
nullptr, 0, nullptr, 0, type));
2578+
}
2579+
25712580
if( init_expr ) {
25722581
value = ASRUtils::expr_value(init_expr);
25732582
SetChar variable_dependencies_vec;

0 commit comments

Comments
 (0)