Skip to content

Commit 521b549

Browse files
committed
Return list[i32] directly from type_to_str_python
1 parent ea2de82 commit 521b549

File tree

6 files changed

+9
-8
lines changed

6 files changed

+9
-8
lines changed

src/libasr/asr_utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ static inline std::string type_to_str_python(const ASR::ttype_t *t)
203203
return "dict";
204204
}
205205
case ASR::ttypeType::List: {
206-
return "list";
206+
ASR::List_t *l = (ASR::List_t *)t;
207+
return "list[" + type_to_str_python(l->m_type) + "]";
207208
}
208209
default : throw LFortranException("Not implemented");
209210
}

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,15 +817,15 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
817817
} else if (ASR::is_a<ASR::List_t>(*left_type) && ASR::is_a<ASR::List_t>(*right_type)
818818
&& op == ASR::binopType::Add) {
819819
dest_type = left_type;
820+
std::string ltype = ASRUtils::type_to_str_python(left_type);
821+
std::string rtype = ASRUtils::type_to_str_python(right_type);
820822
ASR::ttype_t *left_type2 = ASR::down_cast<ASR::List_t>(left_type)->m_type;
821823
ASR::ttype_t *right_type2 = ASR::down_cast<ASR::List_t>(right_type)->m_type;
822-
std::string ltype = ASRUtils::type_to_str_python(left_type2);
823-
std::string rtype = ASRUtils::type_to_str_python(right_type2);
824824
if (!ASRUtils::check_equal_type(left_type2, right_type2)) {
825825
diag.add(diag::Diagnostic(
826826
"Both the lists should be of the same type for concatenation.",
827827
diag::Level::Error, diag::Stage::Semantic, {
828-
diag::Label("type mismatch (list[" + ltype + "] and list[" + rtype + "])",
828+
diag::Label("type mismatch ('" + ltype + "' and '" + rtype + "')",
829829
{left->base.loc, right->base.loc})
830830
})
831831
);

tests/reference/asr-test_annassign_type_mismatch-7dac7be.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"stdout": null,
99
"stdout_hash": null,
1010
"stderr": "asr-test_annassign_type_mismatch-7dac7be.stderr",
11-
"stderr_hash": "bfab695051d2c56840fc857f37657f57711798f14335572d597efef3",
11+
"stderr_hash": "2e2230047083bb3431865114def04970e6c69c261d97bc7b05ecf365",
1212
"returncode": 2
1313
}

tests/reference/asr-test_annassign_type_mismatch-7dac7be.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ semantic error: Type mismatch in annotation-assignment, the types must be compat
22
--> tests/errors/test_annassign_type_mismatch.py:4:5
33
|
44
4 | x: i32[4] = [1, 2, 3, 4]
5-
| ^ ^^^^^^^^^^^^ type mismatch ('i32' and 'list')
5+
| ^ ^^^^^^^^^^^^ type mismatch ('i32' and 'list[i32]')

tests/reference/asr-test_list_concat-41d186f.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"stdout": null,
99
"stdout_hash": null,
1010
"stderr": "asr-test_list_concat-41d186f.stderr",
11-
"stderr_hash": "3d66fb0c1b47082ba625a9589b9023954e821cd7e6fdb760b4aae992",
11+
"stderr_hash": "40b83e988e6e02beadaeeafbed4b29e65c985dfd596dd1d0f4a7bd3f",
1212
"returncode": 2
1313
}

tests/reference/asr-test_list_concat-41d186f.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ semantic error: Both the lists should be of the same type for concatenation.
22
--> tests/errors/test_list_concat.py:8:3
33
|
44
8 | a += b
5-
| ^ ^ type mismatch (list[i32] and list[f32])
5+
| ^ ^ type mismatch ('list[i32]' and 'list[f32]')

0 commit comments

Comments
 (0)