diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index da49d33249..d4509dd64a 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -1590,6 +1590,15 @@ class CommonVisitor : public AST::BaseVisitor { } } + bool is_hashable(ASR::ttype_t* object_type) { + if (ASR::is_a(*object_type) + || ASR::is_a(*object_type) + || ASR::is_a(*object_type)) { + return false; + } + return true; + } + AST::expr_t* get_var_intent_and_annotation(AST::expr_t *annotation, ASR::intentType &intent) { if (AST::is_a(*annotation)) { AST::Subscript_t *s = AST::down_cast(annotation); @@ -1701,6 +1710,17 @@ class CommonVisitor : public AST::BaseVisitor { if (AST::is_a(*s->m_slice) || AST::is_a(*s->m_slice)) { ASR::ttype_t *type = ast_expr_to_asr_type(loc, *s->m_slice, is_allocatable, is_const, raise_error, abi, is_argument); + if (!is_hashable(type)) { + diag.add(diag::Diagnostic( + "Unhashable type: '" + ASRUtils::type_to_str(type) + "'", + diag::Level::Error, diag::Stage::Semantic, { + diag::Label("Mutable type '" + ASRUtils::type_to_str(type) + + "' cannot be stored in a set.", + {s->m_slice->base.loc}) + }) + ); + throw SemanticAbort(); + } return ASRUtils::TYPE(ASR::make_Set_t(al, loc, type)); } else { throw SemanticError("Only Name in Subscript supported for now in `set`" @@ -1736,6 +1756,17 @@ class CommonVisitor : public AST::BaseVisitor { } ASR::ttype_t *key_type = ast_expr_to_asr_type(loc, *t->m_elts[0], is_allocatable, is_const, raise_error, abi, is_argument); + if (!is_hashable(key_type)) { + diag.add(diag::Diagnostic( + "Unhashable type: '" + ASRUtils::type_to_str(key_type) + "'", + diag::Level::Error, diag::Stage::Semantic, { + diag::Label("Mutable type '" + ASRUtils::type_to_str(key_type) + + "' cannot become a key in dict. Hint: Use an immutable type for key.", + {t->m_elts[0]->base.loc}) + }) + ); + throw SemanticAbort(); + } ASR::ttype_t *value_type = ast_expr_to_asr_type(loc, *t->m_elts[1], is_allocatable, is_const, raise_error, abi, is_argument); raise_error_when_dict_key_is_float_or_complex(key_type, loc); @@ -3779,7 +3810,7 @@ class CommonVisitor : public AST::BaseVisitor { ai.m_step, type, nullptr); return false; } else if (ASR::is_a(*type)) { - throw SemanticError("unhashable type in dict: 'slice'", loc); + throw SemanticError("Unhashable type in dict: 'slice'", loc); } } else if(AST::is_a(*m_slice) && ASRUtils::is_array(type)) { @@ -6096,6 +6127,17 @@ class BodyVisitor : public CommonVisitor { ASR::expr_t *key = ASRUtils::EXPR(tmp); if (key_type == nullptr) { key_type = ASRUtils::expr_type(key); + if (!is_hashable(key_type)) { + diag.add(diag::Diagnostic( + "Unhashable type: '" + ASRUtils::type_to_str(key_type) + "'", + diag::Level::Error, diag::Stage::Semantic, { + diag::Label("Mutable type '" + ASRUtils::type_to_str(key_type) + + "' cannot become a key in dict. Hint: Use an immutable type for key.", + {key->base.loc}) + }) + ); + throw SemanticAbort(); + } } else { if (!ASRUtils::check_equal_type(ASRUtils::expr_type(key), key_type)) { throw SemanticError("All dictionary keys must be of the same type", @@ -6565,6 +6607,17 @@ class BodyVisitor : public CommonVisitor { ASR::expr_t *value = ASRUtils::EXPR(tmp); if (type == nullptr) { type = ASRUtils::expr_type(value); + if (!is_hashable(type)) { + diag.add(diag::Diagnostic( + "Unhashable type: '" + ASRUtils::type_to_str(type) + "'", + diag::Level::Error, diag::Stage::Semantic, { + diag::Label("Mutable type '" + ASRUtils::type_to_str(type) + + "' cannot be stored in a set.", + {value->base.loc}) + }) + ); + throw SemanticAbort(); + } } else { if (!ASRUtils::check_equal_type(ASRUtils::expr_type(value), type)) { throw SemanticError("All Set values must be of the same type for now", diff --git a/tests/errors/test_dict_key1.py b/tests/errors/test_dict_key1.py new file mode 100644 index 0000000000..335d4909f0 --- /dev/null +++ b/tests/errors/test_dict_key1.py @@ -0,0 +1,6 @@ +from lpython import i32 + +def test_dict_key1(): + my_dict: dict[list[i32], str] = {[1, 2]: "first", [3, 4]: "second"} + +test_dict_key1() \ No newline at end of file diff --git a/tests/errors/test_dict_key2.py b/tests/errors/test_dict_key2.py new file mode 100644 index 0000000000..dad9b73bf7 --- /dev/null +++ b/tests/errors/test_dict_key2.py @@ -0,0 +1,6 @@ +from lpython import i32 + +def test_dict_key2(): + my_dict: dict[dict[i32, str], str] = {{1: "a", 2: "b"}: "first", {3: "c", 4: "d"}: "second"} + +test_dict_key2() \ No newline at end of file diff --git a/tests/errors/test_dict_key3.py b/tests/errors/test_dict_key3.py new file mode 100644 index 0000000000..c9f682bd06 --- /dev/null +++ b/tests/errors/test_dict_key3.py @@ -0,0 +1,6 @@ +from lpython import i32 + +def test_dict_key3(): + my_dict: dict[set[str], str] = {{1, 2}: "first", {3, 4}: "second"} + +test_dict_key3() \ No newline at end of file diff --git a/tests/errors/test_dict_key4.py b/tests/errors/test_dict_key4.py new file mode 100644 index 0000000000..d947ed6f6c --- /dev/null +++ b/tests/errors/test_dict_key4.py @@ -0,0 +1,4 @@ +def test_dict_key4(): + print({[1, 2]: "first", [3, 4]: "second"}) + +test_dict_key4() \ No newline at end of file diff --git a/tests/errors/test_dict_key5.py b/tests/errors/test_dict_key5.py new file mode 100644 index 0000000000..567844db73 --- /dev/null +++ b/tests/errors/test_dict_key5.py @@ -0,0 +1,4 @@ +def test_dict_key5(): + print({{1: "a", 2: "b"}: "first", {3: "c", 4: "d"}: "second"}) + +test_dict_key5() \ No newline at end of file diff --git a/tests/errors/test_dict_key6.py b/tests/errors/test_dict_key6.py new file mode 100644 index 0000000000..fa5f5e6719 --- /dev/null +++ b/tests/errors/test_dict_key6.py @@ -0,0 +1,4 @@ +def test_dict_key6(): + print({{1, 2}: "first", {3, 4}: "second"}) + +test_dict_key6() \ No newline at end of file diff --git a/tests/errors/test_set_object1.py b/tests/errors/test_set_object1.py new file mode 100644 index 0000000000..7c73f6bbf0 --- /dev/null +++ b/tests/errors/test_set_object1.py @@ -0,0 +1,6 @@ +from lpython import i32 + +def test_set_object1(): + my_set: set[list[i32]] = {[1, 2], [3, 4]} + +test_set_object1() \ No newline at end of file diff --git a/tests/errors/test_set_object2.py b/tests/errors/test_set_object2.py new file mode 100644 index 0000000000..1d21dd6cad --- /dev/null +++ b/tests/errors/test_set_object2.py @@ -0,0 +1,6 @@ +from lpython import i32 + +def test_set_object2(): + my_set: set[dict[i32, str]] = {{1: "a", 2: "b"}, {3: "c", 4: "d"}} + +test_set_object2() \ No newline at end of file diff --git a/tests/errors/test_set_object3.py b/tests/errors/test_set_object3.py new file mode 100644 index 0000000000..e49693569a --- /dev/null +++ b/tests/errors/test_set_object3.py @@ -0,0 +1,6 @@ +from lpython import i32 + +def test_set_object3(): + my_set: set[set[i32]] = {{1, 2}, {3, 4}} + +test_set_object3() \ No newline at end of file diff --git a/tests/errors/test_set_object4.py b/tests/errors/test_set_object4.py new file mode 100644 index 0000000000..07b2f64d43 --- /dev/null +++ b/tests/errors/test_set_object4.py @@ -0,0 +1,4 @@ +def test_set_object4(): + print({[1, 2], [3, 4]}) + +test_set_object4() \ No newline at end of file diff --git a/tests/errors/test_set_object5.py b/tests/errors/test_set_object5.py new file mode 100644 index 0000000000..fd66665416 --- /dev/null +++ b/tests/errors/test_set_object5.py @@ -0,0 +1,4 @@ +def test_set_object5(): + print({{1: "a", 2: "b"}, {3: "c", 4: "d"}}) + +test_set_object5() \ No newline at end of file diff --git a/tests/errors/test_set_object6.py b/tests/errors/test_set_object6.py new file mode 100644 index 0000000000..e25c9e27aa --- /dev/null +++ b/tests/errors/test_set_object6.py @@ -0,0 +1,4 @@ +def test_set_object6(): + print({{1, 2}, {3, 4}}) + +test_set_object6() \ No newline at end of file diff --git a/tests/reference/asr-test_dict7-1415e14.json b/tests/reference/asr-test_dict7-1415e14.json index 64eb4e7eb3..c8b2efc736 100644 --- a/tests/reference/asr-test_dict7-1415e14.json +++ b/tests/reference/asr-test_dict7-1415e14.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-test_dict7-1415e14.stderr", - "stderr_hash": "a51d1d4a46839e1f4258410e979ba83a14abe8c011482e30be2336cd", + "stderr_hash": "843409ee199a2581d9cd1abab45bb59e5e0372d56ef94f1b15aea584", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-test_dict7-1415e14.stderr b/tests/reference/asr-test_dict7-1415e14.stderr index 7884efa64e..4ec6a0fd47 100644 --- a/tests/reference/asr-test_dict7-1415e14.stderr +++ b/tests/reference/asr-test_dict7-1415e14.stderr @@ -1,4 +1,4 @@ -semantic error: unhashable type in dict: 'slice' +semantic error: Unhashable type in dict: 'slice' --> tests/errors/test_dict7.py:4:11 | 4 | print(d[1:2]) diff --git a/tests/reference/asr-test_dict_key1-6e57a28.json b/tests/reference/asr-test_dict_key1-6e57a28.json new file mode 100644 index 0000000000..6b3278486d --- /dev/null +++ b/tests/reference/asr-test_dict_key1-6e57a28.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_dict_key1-6e57a28", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_dict_key1.py", + "infile_hash": "0ee4ab5e47edab5de323d7cf97cf3e726e54882e4a5fadb82ee9aedc", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_dict_key1-6e57a28.stderr", + "stderr_hash": "4ee828a6b9a93bfb8285c2006843243b5327f915f9548a2f1b3f1480", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_dict_key1-6e57a28.stderr b/tests/reference/asr-test_dict_key1-6e57a28.stderr new file mode 100644 index 0000000000..b40e2d0071 --- /dev/null +++ b/tests/reference/asr-test_dict_key1-6e57a28.stderr @@ -0,0 +1,5 @@ +semantic error: Unhashable type: 'list' + --> tests/errors/test_dict_key1.py:4:19 + | +4 | my_dict: dict[list[i32], str] = {[1, 2]: "first", [3, 4]: "second"} + | ^^^^^^^^^ Mutable type 'list' cannot become a key in dict. Hint: Use an immutable type for key. diff --git a/tests/reference/asr-test_dict_key2-18ea6fb.json b/tests/reference/asr-test_dict_key2-18ea6fb.json new file mode 100644 index 0000000000..ade413fcb2 --- /dev/null +++ b/tests/reference/asr-test_dict_key2-18ea6fb.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_dict_key2-18ea6fb", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_dict_key2.py", + "infile_hash": "25b325264991082018c989f990a6b71409e7af0df4a27e5b5142a349", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_dict_key2-18ea6fb.stderr", + "stderr_hash": "5883683aaf0a4ae56b5fd86f56f6900e3e752a72bc675af9c607d998", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_dict_key2-18ea6fb.stderr b/tests/reference/asr-test_dict_key2-18ea6fb.stderr new file mode 100644 index 0000000000..1ffcdc218e --- /dev/null +++ b/tests/reference/asr-test_dict_key2-18ea6fb.stderr @@ -0,0 +1,5 @@ +semantic error: Unhashable type: 'dict' + --> tests/errors/test_dict_key2.py:4:19 + | +4 | my_dict: dict[dict[i32, str], str] = {{1: "a", 2: "b"}: "first", {3: "c", 4: "d"}: "second"} + | ^^^^^^^^^^^^^^ Mutable type 'dict' cannot become a key in dict. Hint: Use an immutable type for key. diff --git a/tests/reference/asr-test_dict_key3-9fc7793.json b/tests/reference/asr-test_dict_key3-9fc7793.json new file mode 100644 index 0000000000..4969639001 --- /dev/null +++ b/tests/reference/asr-test_dict_key3-9fc7793.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_dict_key3-9fc7793", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_dict_key3.py", + "infile_hash": "9675711d37ed0e58ddd82a53ec580cc21c58a9b94ad598b706fb78f8", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_dict_key3-9fc7793.stderr", + "stderr_hash": "bd995f8512a83892aa1be985c6f7ff1761691829150549ba4ac84f17", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_dict_key3-9fc7793.stderr b/tests/reference/asr-test_dict_key3-9fc7793.stderr new file mode 100644 index 0000000000..003e11adcf --- /dev/null +++ b/tests/reference/asr-test_dict_key3-9fc7793.stderr @@ -0,0 +1,5 @@ +semantic error: Unhashable type: 'set' + --> tests/errors/test_dict_key3.py:4:19 + | +4 | my_dict: dict[set[str], str] = {{1, 2}: "first", {3, 4}: "second"} + | ^^^^^^^^ Mutable type 'set' cannot become a key in dict. Hint: Use an immutable type for key. diff --git a/tests/reference/asr-test_dict_key4-dc7abfc.json b/tests/reference/asr-test_dict_key4-dc7abfc.json new file mode 100644 index 0000000000..c963a564ce --- /dev/null +++ b/tests/reference/asr-test_dict_key4-dc7abfc.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_dict_key4-dc7abfc", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_dict_key4.py", + "infile_hash": "197ac00a9a0a5763f939d8b5aec2e33a5b3ec769d93149a1c93999c1", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_dict_key4-dc7abfc.stderr", + "stderr_hash": "ff55c824acc6a3bc2c7f8845b345bcf5d66d13374526ab958a005dc7", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_dict_key4-dc7abfc.stderr b/tests/reference/asr-test_dict_key4-dc7abfc.stderr new file mode 100644 index 0000000000..29a30eee32 --- /dev/null +++ b/tests/reference/asr-test_dict_key4-dc7abfc.stderr @@ -0,0 +1,5 @@ +semantic error: Unhashable type: 'list' + --> tests/errors/test_dict_key4.py:2:12 + | +2 | print({[1, 2]: "first", [3, 4]: "second"}) + | ^^^^^^ Mutable type 'list' cannot become a key in dict. Hint: Use an immutable type for key. diff --git a/tests/reference/asr-test_dict_key5-87496d1.json b/tests/reference/asr-test_dict_key5-87496d1.json new file mode 100644 index 0000000000..25468dfeee --- /dev/null +++ b/tests/reference/asr-test_dict_key5-87496d1.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_dict_key5-87496d1", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_dict_key5.py", + "infile_hash": "08a7118a664a5ac63f470b5a47d19ed7c35a06e3c8ae40a7b44010ea", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_dict_key5-87496d1.stderr", + "stderr_hash": "c7ae39bf80d3a6d1817fbd7aba5455e96623b1225abeb9428af2c73a", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_dict_key5-87496d1.stderr b/tests/reference/asr-test_dict_key5-87496d1.stderr new file mode 100644 index 0000000000..1a7063742b --- /dev/null +++ b/tests/reference/asr-test_dict_key5-87496d1.stderr @@ -0,0 +1,5 @@ +semantic error: Unhashable type: 'dict' + --> tests/errors/test_dict_key5.py:2:12 + | +2 | print({{1: "a", 2: "b"}: "first", {3: "c", 4: "d"}: "second"}) + | ^^^^^^^^^^^^^^^^ Mutable type 'dict' cannot become a key in dict. Hint: Use an immutable type for key. diff --git a/tests/reference/asr-test_dict_key6-1d334b2.json b/tests/reference/asr-test_dict_key6-1d334b2.json new file mode 100644 index 0000000000..9674df4357 --- /dev/null +++ b/tests/reference/asr-test_dict_key6-1d334b2.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_dict_key6-1d334b2", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_dict_key6.py", + "infile_hash": "14ea00618e1414afe9f93d0aa0d4fd5b4332883465126cbba6faab76", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_dict_key6-1d334b2.stderr", + "stderr_hash": "74a8ee0549333b4659afc7deec824a14bbc672316b22e3c99a026846", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_dict_key6-1d334b2.stderr b/tests/reference/asr-test_dict_key6-1d334b2.stderr new file mode 100644 index 0000000000..5751e6f1f1 --- /dev/null +++ b/tests/reference/asr-test_dict_key6-1d334b2.stderr @@ -0,0 +1,5 @@ +semantic error: Unhashable type: 'set' + --> tests/errors/test_dict_key6.py:2:12 + | +2 | print({{1, 2}: "first", {3, 4}: "second"}) + | ^^^^^^ Mutable type 'set' cannot become a key in dict. Hint: Use an immutable type for key. diff --git a/tests/reference/asr-test_set_object1-d9bd2e1.json b/tests/reference/asr-test_set_object1-d9bd2e1.json new file mode 100644 index 0000000000..c0c83abc12 --- /dev/null +++ b/tests/reference/asr-test_set_object1-d9bd2e1.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_set_object1-d9bd2e1", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_set_object1.py", + "infile_hash": "9450d7ca46f30271944800137d28413648bafdbeb7f0a7ac0906c832", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_set_object1-d9bd2e1.stderr", + "stderr_hash": "b528f86f591ab403348d8dd5037d2385fdb7ce29501215a69d10702f", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_set_object1-d9bd2e1.stderr b/tests/reference/asr-test_set_object1-d9bd2e1.stderr new file mode 100644 index 0000000000..a477ff5943 --- /dev/null +++ b/tests/reference/asr-test_set_object1-d9bd2e1.stderr @@ -0,0 +1,5 @@ +semantic error: Unhashable type: 'list' + --> tests/errors/test_set_object1.py:4:17 + | +4 | my_set: set[list[i32]] = {[1, 2], [3, 4]} + | ^^^^^^^^^ Mutable type 'list' cannot be stored in a set. diff --git a/tests/reference/asr-test_set_object2-41401ff.json b/tests/reference/asr-test_set_object2-41401ff.json new file mode 100644 index 0000000000..b19b8f5fbe --- /dev/null +++ b/tests/reference/asr-test_set_object2-41401ff.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_set_object2-41401ff", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_set_object2.py", + "infile_hash": "e7360eff7caf0991c5bd4c505a947d23e2bc01277e9a2966362400df", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_set_object2-41401ff.stderr", + "stderr_hash": "4fe845a8f949fce5b955b86d5a5ad60f0e1ae84e3c17b01572d37e2a", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_set_object2-41401ff.stderr b/tests/reference/asr-test_set_object2-41401ff.stderr new file mode 100644 index 0000000000..d0103d57ad --- /dev/null +++ b/tests/reference/asr-test_set_object2-41401ff.stderr @@ -0,0 +1,5 @@ +semantic error: Unhashable type: 'dict' + --> tests/errors/test_set_object2.py:4:17 + | +4 | my_set: set[dict[i32, str]] = {{1: "a", 2: "b"}, {3: "c", 4: "d"}} + | ^^^^^^^^^^^^^^ Mutable type 'dict' cannot be stored in a set. diff --git a/tests/reference/asr-test_set_object3-680b593.json b/tests/reference/asr-test_set_object3-680b593.json new file mode 100644 index 0000000000..08ac056d6b --- /dev/null +++ b/tests/reference/asr-test_set_object3-680b593.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_set_object3-680b593", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_set_object3.py", + "infile_hash": "f1dea0a951aa880721aa38a0dcf254983e7d50ab408c64c87b9a078e", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_set_object3-680b593.stderr", + "stderr_hash": "05d3a6338fd929fef485c7403500a1f2111dc8e638a3369ff942bea2", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_set_object3-680b593.stderr b/tests/reference/asr-test_set_object3-680b593.stderr new file mode 100644 index 0000000000..586a64956b --- /dev/null +++ b/tests/reference/asr-test_set_object3-680b593.stderr @@ -0,0 +1,5 @@ +semantic error: Unhashable type: 'set' + --> tests/errors/test_set_object3.py:4:17 + | +4 | my_set: set[set[i32]] = {{1, 2}, {3, 4}} + | ^^^^^^^^ Mutable type 'set' cannot be stored in a set. diff --git a/tests/reference/asr-test_set_object4-243eb04.json b/tests/reference/asr-test_set_object4-243eb04.json new file mode 100644 index 0000000000..fb330cac95 --- /dev/null +++ b/tests/reference/asr-test_set_object4-243eb04.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_set_object4-243eb04", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_set_object4.py", + "infile_hash": "0b339aaa798fca7bd12920c583b0d60d70fe2f8afeb68a1811992f59", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_set_object4-243eb04.stderr", + "stderr_hash": "dff44d0e30f3fed351e8df2bc1875c3a9972db927a58400df456ec12", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_set_object4-243eb04.stderr b/tests/reference/asr-test_set_object4-243eb04.stderr new file mode 100644 index 0000000000..fc808c1ffc --- /dev/null +++ b/tests/reference/asr-test_set_object4-243eb04.stderr @@ -0,0 +1,5 @@ +semantic error: Unhashable type: 'list' + --> tests/errors/test_set_object4.py:2:12 + | +2 | print({[1, 2], [3, 4]}) + | ^^^^^^ Mutable type 'list' cannot be stored in a set. diff --git a/tests/reference/asr-test_set_object5-4bd1044.json b/tests/reference/asr-test_set_object5-4bd1044.json new file mode 100644 index 0000000000..891f62f787 --- /dev/null +++ b/tests/reference/asr-test_set_object5-4bd1044.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_set_object5-4bd1044", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_set_object5.py", + "infile_hash": "6d88885bb6428fe2b63121d653dcdfd23ec30d6b5322eb4cb8faada6", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_set_object5-4bd1044.stderr", + "stderr_hash": "8727cfdabeed50ccf7989653e6607ebc8cb8b828c7388378d0fc33a6", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_set_object5-4bd1044.stderr b/tests/reference/asr-test_set_object5-4bd1044.stderr new file mode 100644 index 0000000000..0390d86eec --- /dev/null +++ b/tests/reference/asr-test_set_object5-4bd1044.stderr @@ -0,0 +1,5 @@ +semantic error: Unhashable type: 'dict' + --> tests/errors/test_set_object5.py:2:12 + | +2 | print({{1: "a", 2: "b"}, {3: "c", 4: "d"}}) + | ^^^^^^^^^^^^^^^^ Mutable type 'dict' cannot be stored in a set. diff --git a/tests/reference/asr-test_set_object6-01b4fa7.json b/tests/reference/asr-test_set_object6-01b4fa7.json new file mode 100644 index 0000000000..50c10ffa49 --- /dev/null +++ b/tests/reference/asr-test_set_object6-01b4fa7.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_set_object6-01b4fa7", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_set_object6.py", + "infile_hash": "528a4e950b464e2915259ef826f2322c55efc268b2b5245add9fb6be", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_set_object6-01b4fa7.stderr", + "stderr_hash": "45b2d173c7081a5410321802a3055c10e6277ec48ad0f2d1ef4dc60e", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_set_object6-01b4fa7.stderr b/tests/reference/asr-test_set_object6-01b4fa7.stderr new file mode 100644 index 0000000000..7d7c9c9098 --- /dev/null +++ b/tests/reference/asr-test_set_object6-01b4fa7.stderr @@ -0,0 +1,5 @@ +semantic error: Unhashable type: 'set' + --> tests/errors/test_set_object6.py:2:12 + | +2 | print({{1, 2}, {3, 4}}) + | ^^^^^^ Mutable type 'set' cannot be stored in a set. diff --git a/tests/tests.toml b/tests/tests.toml index be2061fe97..1f4706fd79 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -1021,6 +1021,54 @@ asr = true filename = "errors/test_dict1.py" asr = true +[[test]] +filename = "errors/test_dict_key1.py" +asr = true + +[[test]] +filename = "errors/test_dict_key2.py" +asr = true + +[[test]] +filename = "errors/test_dict_key3.py" +asr = true + +[[test]] +filename = "errors/test_dict_key4.py" +asr = true + +[[test]] +filename = "errors/test_dict_key5.py" +asr = true + +[[test]] +filename = "errors/test_dict_key6.py" +asr = true + +[[test]] +filename = "errors/test_set_object1.py" +asr = true + +[[test]] +filename = "errors/test_set_object2.py" +asr = true + +[[test]] +filename = "errors/test_set_object3.py" +asr = true + +[[test]] +filename = "errors/test_set_object4.py" +asr = true + +[[test]] +filename = "errors/test_set_object5.py" +asr = true + +[[test]] +filename = "errors/test_set_object6.py" +asr = true + [[test]] filename = "errors/test_dict8.py" asr = true