diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index 4ee368a594..5883c7e1a0 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -162,13 +162,30 @@ static inline std::string type_to_str_python(const ASR::ttype_t *t) { switch (t->type) { case ASR::ttypeType::Integer: { - return "int"; + ASR::Integer_t *i = (ASR::Integer_t*)t; + switch (i->m_kind) { + case 1: { return "i8"; } + case 2: { return "i16"; } + case 4: { return "i32"; } + case 8: { return "i64"; } + default: { throw LFortranException("Integer kind not supported"); } + } } case ASR::ttypeType::Real: { - return "float"; + ASR::Real_t *r = (ASR::Real_t*)t; + switch (r->m_kind) { + case 4: { return "f32"; } + case 8: { return "f64"; } + default: { throw LFortranException("Float kind not supported"); } + } } case ASR::ttypeType::Complex: { - return "complex"; + ASR::Complex_t *c = (ASR::Complex_t*)t; + switch (c->m_kind) { + case 4: { return "c32"; } + case 8: { return "c64"; } + default: { throw LFortranException("Complex kind not supported"); } + } } case ASR::ttypeType::Logical: { return "bool"; @@ -186,7 +203,8 @@ static inline std::string type_to_str_python(const ASR::ttype_t *t) return "dict"; } case ASR::ttypeType::List: { - return "list"; + ASR::List_t *l = (ASR::List_t *)t; + return "list[" + type_to_str_python(l->m_type) + "]"; } default : throw LFortranException("Not implemented"); } diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index f1e50c5d93..4e0353f1f9 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -817,15 +817,15 @@ class CommonVisitor : public AST::BaseVisitor { } else if (ASR::is_a(*left_type) && ASR::is_a(*right_type) && op == ASR::binopType::Add) { dest_type = left_type; + std::string ltype = ASRUtils::type_to_str_python(left_type); + std::string rtype = ASRUtils::type_to_str_python(right_type); ASR::ttype_t *left_type2 = ASR::down_cast(left_type)->m_type; ASR::ttype_t *right_type2 = ASR::down_cast(right_type)->m_type; - std::string ltype = ASRUtils::type_to_str_python(left_type2); - std::string rtype = ASRUtils::type_to_str_python(right_type2); if (!ASRUtils::check_equal_type(left_type2, right_type2)) { diag.add(diag::Diagnostic( "Both the lists should be of the same type for concatenation.", diag::Level::Error, diag::Stage::Semantic, { - diag::Label("type mismatch (list[" + ltype + "] and list[" + rtype + "])", + diag::Label("type mismatch ('" + ltype + "' and '" + rtype + "')", {left->base.loc, right->base.loc}) }) ); diff --git a/tests/reference/asr-test_annassign_type_mismatch-7dac7be.json b/tests/reference/asr-test_annassign_type_mismatch-7dac7be.json index c0c9020f34..b4b8bf736d 100644 --- a/tests/reference/asr-test_annassign_type_mismatch-7dac7be.json +++ b/tests/reference/asr-test_annassign_type_mismatch-7dac7be.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-test_annassign_type_mismatch-7dac7be.stderr", - "stderr_hash": "568f25869fd6c0d11300ad6095d4994eedbb4e2b538f23c8e34e020c", + "stderr_hash": "2e2230047083bb3431865114def04970e6c69c261d97bc7b05ecf365", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-test_annassign_type_mismatch-7dac7be.stderr b/tests/reference/asr-test_annassign_type_mismatch-7dac7be.stderr index 87a35bba9c..8b597822c2 100644 --- a/tests/reference/asr-test_annassign_type_mismatch-7dac7be.stderr +++ b/tests/reference/asr-test_annassign_type_mismatch-7dac7be.stderr @@ -2,4 +2,4 @@ semantic error: Type mismatch in annotation-assignment, the types must be compat --> tests/errors/test_annassign_type_mismatch.py:4:5 | 4 | x: i32[4] = [1, 2, 3, 4] - | ^ ^^^^^^^^^^^^ type mismatch ('int' and 'list') + | ^ ^^^^^^^^^^^^ type mismatch ('i32' and 'list[i32]') diff --git a/tests/reference/asr-test_append_type_mismatch-030e9c7.json b/tests/reference/asr-test_append_type_mismatch-030e9c7.json index 1110983fa2..23222c2c05 100644 --- a/tests/reference/asr-test_append_type_mismatch-030e9c7.json +++ b/tests/reference/asr-test_append_type_mismatch-030e9c7.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-test_append_type_mismatch-030e9c7.stderr", - "stderr_hash": "6a14ee224ad1fd27e0d28e1f33d4a96b858663aae7d07bca8987575d", + "stderr_hash": "a59a2722e83e531fd9a27bdc31ad61af475a178dcce48c75a1d62595", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-test_append_type_mismatch-030e9c7.stderr b/tests/reference/asr-test_append_type_mismatch-030e9c7.stderr index 309e283f22..f1d9883367 100644 --- a/tests/reference/asr-test_append_type_mismatch-030e9c7.stderr +++ b/tests/reference/asr-test_append_type_mismatch-030e9c7.stderr @@ -1,4 +1,4 @@ -semantic error: Type mismatch while appending to a list, found ('str' and 'int'). +semantic error: Type mismatch while appending to a list, found ('str' and 'i32'). --> tests/errors/test_append_type_mismatch.py:6:5 | 6 | l.append('a') diff --git a/tests/reference/asr-test_list1-73fd538.json b/tests/reference/asr-test_list1-73fd538.json index 205a4c7b11..72c7b1d4db 100644 --- a/tests/reference/asr-test_list1-73fd538.json +++ b/tests/reference/asr-test_list1-73fd538.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-test_list1-73fd538.stderr", - "stderr_hash": "4bda0c0451782d4d487da271e484718ac1efc9fbe001e4d8e122bfc0", + "stderr_hash": "7143db86381df6ff92cb7432deb228b51302b10edb703cf57e8aaec1", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-test_list1-73fd538.stderr b/tests/reference/asr-test_list1-73fd538.stderr index 39eea1e14f..a99b1b4a06 100644 --- a/tests/reference/asr-test_list1-73fd538.stderr +++ b/tests/reference/asr-test_list1-73fd538.stderr @@ -1,4 +1,4 @@ -semantic error: Type mismatch while removing from a list, found ('str' and 'int'). +semantic error: Type mismatch while removing from a list, found ('str' and 'i32'). --> tests/errors/test_list1.py:6:5 | 6 | a.remove('error') diff --git a/tests/reference/asr-test_list_concat-41d186f.json b/tests/reference/asr-test_list_concat-41d186f.json index 750c2a02aa..5ab89ff790 100644 --- a/tests/reference/asr-test_list_concat-41d186f.json +++ b/tests/reference/asr-test_list_concat-41d186f.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-test_list_concat-41d186f.stderr", - "stderr_hash": "c5c416e09e0aee961b0734b7a491c03e59299c0bca6c6afbbbb0f626", + "stderr_hash": "40b83e988e6e02beadaeeafbed4b29e65c985dfd596dd1d0f4a7bd3f", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-test_list_concat-41d186f.stderr b/tests/reference/asr-test_list_concat-41d186f.stderr index ac67b44ac9..27fc6eabc7 100644 --- a/tests/reference/asr-test_list_concat-41d186f.stderr +++ b/tests/reference/asr-test_list_concat-41d186f.stderr @@ -2,4 +2,4 @@ semantic error: Both the lists should be of the same type for concatenation. --> tests/errors/test_list_concat.py:8:3 | 8 | a += b - | ^ ^ type mismatch (list[int] and list[float]) + | ^ ^ type mismatch ('list[i32]' and 'list[f32]') diff --git a/tests/reference/asr-test_set1-11379c7.json b/tests/reference/asr-test_set1-11379c7.json index 278d1e7fe0..0454b248e2 100644 --- a/tests/reference/asr-test_set1-11379c7.json +++ b/tests/reference/asr-test_set1-11379c7.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-test_set1-11379c7.stderr", - "stderr_hash": "c3c7502dd2515b6cbde6697c886e3d428029e46e4ea5cb8029908cf6", + "stderr_hash": "b876c33be46bf8ce85f551ce68d7edc446e41bd00b65b76d5490e5b5", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-test_set1-11379c7.stderr b/tests/reference/asr-test_set1-11379c7.stderr index 61c0f21555..9a2d202277 100644 --- a/tests/reference/asr-test_set1-11379c7.stderr +++ b/tests/reference/asr-test_set1-11379c7.stderr @@ -1,4 +1,4 @@ -semantic error: Found type mismatch in 'add' ('str' and 'int'). +semantic error: Found type mismatch in 'add' ('str' and 'i32'). --> tests/errors/test_set1.py:6:5 | 6 | a.add('err')