Skip to content

Commit be79690

Browse files
authored
Merge pull request #412 from Smit-create/err-msg
Test error messages
2 parents bffa0a8 + 50c81dc commit be79690

14 files changed

+113
-1
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2497,7 +2497,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
24972497
ASR::expr_t *ele = ASRUtils::EXPR(tmp);
24982498
ASR::ttype_t *ele_type = ASRUtils::expr_type(ele);
24992499
if (!ASRUtils::check_equal_type(ele_type, set_type)) {
2500-
throw SemanticError("Found type mismatch, (" +
2500+
throw SemanticError("Found type mismatch in '" + attr + "'(" +
25012501
ASRUtils::type_to_str(ele_type) + " and " +
25022502
ASRUtils::type_to_str(set_type) + ").", x.base.base.loc);
25032503
}

tests/errors/test_list1.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from ltypes import i32
2+
3+
def test1():
4+
a: list[i32]
5+
a = [1, 2, 3]
6+
a.remove('error')

tests/errors/test_list2.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from ltypes import i32
2+
3+
def test1():
4+
a: list[i32]
5+
a = [1, 2, 3]
6+
a.append(4, 5)

tests/errors/test_set1.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from ltypes import i32
2+
3+
def test1():
4+
a: set[i32]
5+
a = {1, 2, 3}
6+
a.add('err')

tests/errors/test_set2.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from ltypes import i32
2+
3+
def test1():
4+
a: set[i32]
5+
a = {1, 2, 3}
6+
a.remove('error', 'error2')
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "asr-test_list1-73fd538",
3+
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
4+
"infile": "tests/errors/test_list1.py",
5+
"infile_hash": "86f36c119afcaef5c6f790c88c7c517fa6f766bfcc95d121bc16becd",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": null,
9+
"stdout_hash": null,
10+
"stderr": "asr-test_list1-73fd538.stderr",
11+
"stderr_hash": "b09a9abfc3c61d6d4fe93b81ebbfd29ab1494db6d1e7b6a3bd4cba25",
12+
"returncode": 2
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
semantic error: Type mismatch while removing from a list, found (character and integer).
2+
--> tests/errors/test_list1.py:6:5
3+
|
4+
6 | a.remove('error')
5+
| ^^^^^^^^^^^^^^^^^
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "asr-test_list2-10ffdd7",
3+
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
4+
"infile": "tests/errors/test_list2.py",
5+
"infile_hash": "0fde6372e40865fa25b4ef87b0ac31978ae2df367215004cad31a414",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": null,
9+
"stdout_hash": null,
10+
"stderr": "asr-test_list2-10ffdd7.stderr",
11+
"stderr_hash": "be192bc4655f28313c415c7180d676e0383f0acb7e4de75a6b3d1a37",
12+
"returncode": 2
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
semantic error: append() takes exactly one argument
2+
--> tests/errors/test_list2.py:6:5
3+
|
4+
6 | a.append(4, 5)
5+
| ^^^^^^^^^^^^^^
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "asr-test_set1-11379c7",
3+
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
4+
"infile": "tests/errors/test_set1.py",
5+
"infile_hash": "8b09bdc33cffccdb66d9d70f13474d148c5f422ee3892d30fe45eb95",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": null,
9+
"stdout_hash": null,
10+
"stderr": "asr-test_set1-11379c7.stderr",
11+
"stderr_hash": "8b09cefb3289bc45f00ca5a571562e62502aaeab7e92fa8ffeb341e7",
12+
"returncode": 2
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
semantic error: Found type mismatch in 'add'(character and integer).
2+
--> tests/errors/test_set1.py:6:5
3+
|
4+
6 | a.add('err')
5+
| ^^^^^^^^^^^^
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "asr-test_set2-d91a6f0",
3+
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
4+
"infile": "tests/errors/test_set2.py",
5+
"infile_hash": "46c06330c2f51316a178c5d487fb5628d19ffb4e8f95e50653a19fcd",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": null,
9+
"stdout_hash": null,
10+
"stderr": "asr-test_set2-d91a6f0.stderr",
11+
"stderr_hash": "5459ddb5148c630f9374c827aad9c37d25967248002dc0dff5314530",
12+
"returncode": 2
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
semantic error: remove() takes exactly one argument
2+
--> tests/errors/test_set2.py:6:5
3+
|
4+
6 | a.remove('error', 'error2')
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/tests.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,19 @@ asr = true
294294
[[test]]
295295
filename = "errors/test_append_type_mismatch.py"
296296
asr = true
297+
298+
[[test]]
299+
filename = "errors/test_list1.py"
300+
asr = true
301+
302+
[[test]]
303+
filename = "errors/test_list2.py"
304+
asr = true
305+
306+
[[test]]
307+
filename = "errors/test_set1.py"
308+
asr = true
309+
310+
[[test]]
311+
filename = "errors/test_set2.py"
312+
asr = true

0 commit comments

Comments
 (0)