From c8abd471367d90151a99a4eb4052317672cd903e Mon Sep 17 00:00:00 2001 From: Smit-create Date: Tue, 3 May 2022 12:31:58 +0530 Subject: [PATCH 1/3] BUG: fix type check with nested arguments --- src/libasr/asr_utils.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index 7807275de9..dd20695ccb 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -1032,20 +1032,18 @@ inline bool is_same_type_pointer(ASR::ttype_t* source, ASR::ttype_t* dest) { if (ASR::is_a(*x) && ASR::is_a(*y)) { x = ASR::down_cast(x)->m_type; y = ASR::down_cast(y)->m_type; + return check_equal_type(x, y); } else if (ASR::is_a(*x) && ASR::is_a(*y)) { x = ASR::down_cast(x)->m_type; y = ASR::down_cast(y)->m_type; + return check_equal_type(x, y); } else if (ASR::is_a(*x) && ASR::is_a(*y)) { ASR::ttype_t *x_key_type = ASR::down_cast(x)->m_key_type; ASR::ttype_t *y_key_type = ASR::down_cast(y)->m_key_type; ASR::ttype_t *x_value_type = ASR::down_cast(x)->m_value_type; ASR::ttype_t *y_value_type = ASR::down_cast(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; From 3226e00aa8c1691be970bbbb1121fcd2296eeec4 Mon Sep 17 00:00:00 2001 From: Smit-create Date: Tue, 3 May 2022 12:33:07 +0530 Subject: [PATCH 2/3] Add a test --- tests/errors/test_assign5.py | 6 ++++++ tests/tests.toml | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 tests/errors/test_assign5.py diff --git a/tests/errors/test_assign5.py b/tests/errors/test_assign5.py new file mode 100644 index 0000000000..208af15e7d --- /dev/null +++ b/tests/errors/test_assign5.py @@ -0,0 +1,6 @@ +def f(): + x: list[list[i32]] + x = [[1, 2, 3]] + y: list[list[str]] + y = [['a', 'b']] + x = y diff --git a/tests/tests.toml b/tests/tests.toml index 3e1f820f5e..64d3a4d31a 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -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 From 30b3b69724439b831bd0234cd4c2902231a9ce6b Mon Sep 17 00:00:00 2001 From: Smit-create Date: Tue, 3 May 2022 12:33:33 +0530 Subject: [PATCH 3/3] Update tests --- tests/reference/asr-test_assign5-694a98f.json | 13 +++++++++++++ tests/reference/asr-test_assign5-694a98f.stderr | 5 +++++ 2 files changed, 18 insertions(+) create mode 100644 tests/reference/asr-test_assign5-694a98f.json create mode 100644 tests/reference/asr-test_assign5-694a98f.stderr diff --git a/tests/reference/asr-test_assign5-694a98f.json b/tests/reference/asr-test_assign5-694a98f.json new file mode 100644 index 0000000000..312c85ffed --- /dev/null +++ b/tests/reference/asr-test_assign5-694a98f.json @@ -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 +} \ No newline at end of file diff --git a/tests/reference/asr-test_assign5-694a98f.stderr b/tests/reference/asr-test_assign5-694a98f.stderr new file mode 100644 index 0000000000..0847cb828c --- /dev/null +++ b/tests/reference/asr-test_assign5-694a98f.stderr @@ -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]]')