Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/libasr/asr_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,16 @@ static inline std::string type_to_str_python(const ASR::ttype_t *t)
return "str";
}
case ASR::ttypeType::Tuple: {
return "tuple";
ASR::Tuple_t *tup = ASR::down_cast<ASR::Tuple_t>(t);
std::string result = "tuple[";
for (size_t i=0; i<tup->n_type; i++) {
result += type_to_str_python(tup->m_type[i]);
if (i+1 != tup->n_type) {
result += ", ";
}
}
result += "]";
return result;
}
case ASR::ttypeType::Set: {
ASR::Set_t *s = (ASR::Set_t *)t;
Expand Down Expand Up @@ -1084,6 +1093,20 @@ inline bool is_same_type_pointer(ASR::ttype_t* source, ASR::ttype_t* dest) {
ASR::ttype_t *y_value_type = ASR::down_cast<ASR::Dict_t>(y)->m_value_type;
return (check_equal_type(x_key_type, y_key_type) &&
check_equal_type(x_value_type, y_value_type));
} else if (ASR::is_a<ASR::Tuple_t>(*x) && ASR::is_a<ASR::Tuple_t>(*y)) {
ASR::Tuple_t *a = ASR::down_cast<ASR::Tuple_t>(x);
ASR::Tuple_t *b = ASR::down_cast<ASR::Tuple_t>(y);
if(a->n_type != b->n_type) {
return false;
}
bool result = true;
for (size_t i=0; i<a->n_type; i++) {
result = result && check_equal_type(a->m_type[i], b->m_type[i]);
if (!result) {
return false;
}
}
return result;
}
if( x->type == y->type ) {
return true;
Expand Down
5 changes: 5 additions & 0 deletions tests/errors/test_tuple1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def main():
t: tuple[i32, str]
t = (1, 2)

main()
13 changes: 13 additions & 0 deletions tests/reference/asr-test_tuple1-7abe88f.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-test_tuple1-7abe88f",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/test_tuple1.py",
"infile_hash": "4716ea56ce9d57a0d88ffeb9fca4e09204f7a2c1166a5315c4d1245c",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-test_tuple1-7abe88f.stderr",
"stderr_hash": "56df3d46c63077fcdd09c3b54b63e6e096d7d39b2f8cfb61dab0930a",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-test_tuple1-7abe88f.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Type mismatch in assignment, the types must be compatible
--> tests/errors/test_tuple1.py:3:3
|
3 | t = (1, 2)
| ^ ^^^^^^ type mismatch ('tuple[i32, str]' and 'tuple[i32, i32]')
4 changes: 4 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,7 @@ tokens = true
[[test]]
filename = "tokens/errors/paren4.py"
tokens = true

[[test]]
filename = "errors/test_tuple1.py"
asr = true