diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 1538901fe0..221ac09ce4 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -2568,6 +2568,11 @@ class CommonVisitor : public AST::BaseVisitor { ASR::Variable_t* v_variable = ASR::down_cast(v_sym); std::string var_name = v_variable->m_name; ASR::ttype_t* type = v_variable->m_type; + if (!init_expr && ASR::is_a(*type)) { + init_expr = ASRUtils::EXPR(ASR::make_DictConstant_t(al, loc, + nullptr, 0, nullptr, 0, type)); + } + if( init_expr ) { value = ASRUtils::expr_value(init_expr); SetChar variable_dependencies_vec; diff --git a/tests/reference/asr-dictionary1-a105a36.json b/tests/reference/asr-dictionary1-a105a36.json index 991461787d..7191ef6371 100644 --- a/tests/reference/asr-dictionary1-a105a36.json +++ b/tests/reference/asr-dictionary1-a105a36.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-dictionary1-a105a36.stdout", - "stdout_hash": "3ea42309cc8f2201f43bb2fdeb28a85feea890fe49db4063af5c46f8", + "stdout_hash": "ac58817e3dc84de980d646cffeb63540c55bde9ca4229b8a7c58b77a", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-dictionary1-a105a36.stdout b/tests/reference/asr-dictionary1-a105a36.stdout index 8ae305005f..192d0350b7 100644 --- a/tests/reference/asr-dictionary1-a105a36.stdout +++ b/tests/reference/asr-dictionary1-a105a36.stdout @@ -141,6 +141,18 @@ [] [] [(Assignment + (Var 3 x) + (DictConstant + [] + [] + (Dict + (Integer 4) + (Integer 4) + ) + ) + () + ) + (Assignment (Var 3 x) (DictConstant [(IntegerConstant 1 (Integer 4)) @@ -154,6 +166,18 @@ ) () ) + (Assignment + (Var 3 y) + (DictConstant + [] + [] + (Dict + (Character 1 -2 ()) + (Integer 4) + ) + ) + () + ) (Assignment (Var 3 y) (DictConstant @@ -286,6 +310,18 @@ [] [] [(Assignment + (Var 5 y) + (DictConstant + [] + [] + (Dict + (Character 1 -2 ()) + (Integer 4) + ) + ) + () + ) + (Assignment (Var 5 y) (DictConstant [(StringConstant @@ -390,6 +426,18 @@ [] [] [(Assignment + (Var 4 y) + (DictConstant + [] + [] + (Dict + (Character 1 -2 ()) + (Integer 4) + ) + ) + () + ) + (Assignment (Var 4 y) (DictConstant [(StringConstant @@ -494,6 +542,18 @@ [] [] [(Assignment + (Var 6 y) + (DictConstant + [] + [] + (Dict + (Character 1 -2 ()) + (Integer 4) + ) + ) + () + ) + (Assignment (Var 6 y) (DictConstant [(StringConstant @@ -574,7 +634,19 @@ ) [f] [] - [(SubroutineCall + [(Assignment + (Var 8 x) + (DictConstant + [] + [] + (Dict + (Integer 4) + (Integer 4) + ) + ) + () + ) + (SubroutineCall 2 f () [((Var 8 x))] diff --git a/tests/reference/asr-print_list_tuple_03-9de3736.json b/tests/reference/asr-print_list_tuple_03-9de3736.json index 857cf48d38..5a107ca056 100644 --- a/tests/reference/asr-print_list_tuple_03-9de3736.json +++ b/tests/reference/asr-print_list_tuple_03-9de3736.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-print_list_tuple_03-9de3736.stdout", - "stdout_hash": "8962f3d49727ceb8f899acc2382f5fb6d24b16506a154ccf907400f5", + "stdout_hash": "9bc9712a40c386ddbd519614bb9ed900ebde24b5db7d0876f7e88e95", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-print_list_tuple_03-9de3736.stdout b/tests/reference/asr-print_list_tuple_03-9de3736.stdout index 9e0bc45dec..dfd164741e 100644 --- a/tests/reference/asr-print_list_tuple_03-9de3736.stdout +++ b/tests/reference/asr-print_list_tuple_03-9de3736.stdout @@ -110,6 +110,21 @@ [] [] [(Assignment + (Var 3 x) + (DictConstant + [] + [] + (Dict + (Integer 4) + (Tuple + [(Integer 4) + (Integer 4)] + ) + ) + ) + () + ) + (Assignment (Var 3 x) (DictConstant [(IntegerConstant 1 (Integer 4)) @@ -140,6 +155,20 @@ ) () ) + (Assignment + (Var 3 y) + (DictConstant + [] + [] + (Dict + (Integer 4) + (List + (Integer 4) + ) + ) + ) + () + ) (Assignment (Var 3 y) (DictConstant diff --git a/tests/reference/pass_print_list_tuple-print_list_tuple_03-195fa9c.json b/tests/reference/pass_print_list_tuple-print_list_tuple_03-195fa9c.json index c2fa5807d7..7734699e6f 100644 --- a/tests/reference/pass_print_list_tuple-print_list_tuple_03-195fa9c.json +++ b/tests/reference/pass_print_list_tuple-print_list_tuple_03-195fa9c.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "pass_print_list_tuple-print_list_tuple_03-195fa9c.stdout", - "stdout_hash": "f63197ac9c1a649cfb2d3a3ef6f6672964ad753593afc68ce6d567e9", + "stdout_hash": "edb9d31c77ac27a72de4454275693936ef43c07263a2da687e16da5c", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/pass_print_list_tuple-print_list_tuple_03-195fa9c.stdout b/tests/reference/pass_print_list_tuple-print_list_tuple_03-195fa9c.stdout index aa210f8619..98feee42a5 100644 --- a/tests/reference/pass_print_list_tuple-print_list_tuple_03-195fa9c.stdout +++ b/tests/reference/pass_print_list_tuple-print_list_tuple_03-195fa9c.stdout @@ -144,6 +144,21 @@ [] [] [(Assignment + (Var 3 x) + (DictConstant + [] + [] + (Dict + (Integer 4) + (Tuple + [(Integer 4) + (Integer 4)] + ) + ) + ) + () + ) + (Assignment (Var 3 x) (DictConstant [(IntegerConstant 1 (Integer 4)) @@ -174,6 +189,20 @@ ) () ) + (Assignment + (Var 3 y) + (DictConstant + [] + [] + (Dict + (Integer 4) + (List + (Integer 4) + ) + ) + ) + () + ) (Assignment (Var 3 y) (DictConstant