Skip to content

Commit afb9bb6

Browse files
authored
Merge pull request #1009 from czgdp1807/dict04
Allow empty dict initialisation at declaration
2 parents d314f09 + 9f40cc3 commit afb9bb6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

integration_tests/test_dict_01.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from ltypes import i32, f64
22

33
def test_dict():
4-
rollnumber2cpi: dict[i32, f64] = {0: 1.1}
4+
rollnumber2cpi: dict[i32, f64] = {}
55
i: i32
66
size: i32 = 1000
77

8+
rollnumber2cpi[0] = 1.1
9+
810
for i in range(1000, 1000 + size):
911
rollnumber2cpi[i] = float(i/100.0 + 5.0)
1012

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,6 +3328,11 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
33283328

33293329
void visit_Dict(const AST::Dict_t &x) {
33303330
LFORTRAN_ASSERT(x.n_keys == x.n_values);
3331+
if( x.n_keys == 0 && ann_assign_target_type != nullptr ) {
3332+
tmp = ASR::make_DictConstant_t(al, x.base.base.loc, nullptr, 0,
3333+
nullptr, 0, ann_assign_target_type);
3334+
return ;
3335+
}
33313336
Vec<ASR::expr_t*> keys;
33323337
keys.reserve(al, x.n_keys);
33333338
ASR::ttype_t* key_type = nullptr;

0 commit comments

Comments
 (0)