← 输入框|github.com|刷新
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
10 changes: 4 additions & 6 deletions src/libasr/asr_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1032,20 +1032,18 @@ inline bool is_same_type_pointer(ASR::ttype_t* source, ASR::ttype_t* dest) {
if (ASR::is_a<ASR::List_t>(*x) && ASR::is_a<ASR::List_t>(*y)) {
x = ASR::down_cast<ASR::List_t>(x)->m_type;
y = ASR::down_cast<ASR::List_t>(y)->m_type;
return check_equal_type(x, y);
} else if (ASR::is_a<ASR::Set_t>(*x) && ASR::is_a<ASR::Set_t>(*y)) {
x = ASR::down_cast<ASR::Set_t>(x)->m_type;
y = ASR::down_cast<ASR::Set_t>(y)->m_type;
return check_equal_type(x, y);
} else if (ASR::is_a<ASR::Dict_t>(*x) && ASR::is_a<ASR::Dict_t>(*y)) {
ASR::ttype_t *x_key_type = ASR::down_cast<ASR::Dict_t>(x)->m_key_type;
ASR::ttype_t *y_key_type = ASR::down_cast<ASR::Dict_t>(y)->m_key_type;
ASR::ttype_t *x_value_type = ASR::down_cast<ASR::Dict_t>(x)->m_value_type;
ASR::ttype_t *y_value_type = ASR::down_cast<ASR::Dict_t>(y)->m_value_type;
if (x->type == y->type &&
check_equal_type(x_key_type, y_key_type) &&
check_equal_type(x_value_type, y_value_type)) {
return true;
}
return false;
return (check_equal_type(x_key_type, y_key_type) &&
check_equal_type(x_value_type, y_value_type));
}
if( x->type == y->type ) {
return true;
Expand Down
6 changes: 6 additions & 0 deletions tests/errors/test_assign5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def f():
x: list[list[i32]]
x = [[1, 2, 3]]
y: list[list[str]]
y = [['a', 'b']]
x = y
13 changes: 13 additions & 0 deletions tests/reference/asr-test_assign5-694a98f.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-test_assign5-694a98f",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/test_assign5.py",
"infile_hash": "41144111ae3dad56feed42b1b148334a8faef310fbbabde10f3af8df",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-test_assign5-694a98f.stderr",
"stderr_hash": "172b2f13e9b7670cbdd718452713fb15ed4bcd19f6193d328e459fbe",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-test_assign5-694a98f.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_assign5.py:6:5
|
6 | x = y
| ^ ^ type mismatch ('list[list[i32]]' and 'list[list[str]]')
4 changes: 4 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ asr = true
filename = "errors/test_assign4.py"
asr = true

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

[[test]]
filename = "errors/test_binop1.py"
asr = true
Expand Down