Skip to content

Commit fcf70be

Browse files
authored
Merge pull request #1976 from Shaikh-Ubaid/imprv_err_msg
Improve error message for type mismatch in index
2 parents bcd882a + b460478 commit fcf70be

7 files changed

+11
-11
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3629,9 +3629,9 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
36293629
!ASRUtils::is_integer(*ASRUtils::expr_type(ASRUtils::EXPR(tmp)))) {
36303630
std::string fnd = ASRUtils::type_to_str_python(ASRUtils::expr_type(ASRUtils::EXPR(tmp)));
36313631
diag.add(diag::Diagnostic(
3632-
"Type mismatch in index, expected a single integer",
3632+
"Type mismatch in index, expected a single integer or slice",
36333633
diag::Level::Error, diag::Stage::Semantic, {
3634-
diag::Label("type mismatch (found: '" + fnd + "', expected: 'i32')",
3634+
diag::Label("type mismatch (found: '" + fnd + "', expected: 'i32' or slice)",
36353635
{tmp->loc})
36363636
})
36373637
);

tests/reference/asr-string_01-78629c4.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"stdout": null,
99
"stdout_hash": null,
1010
"stderr": "asr-string_01-78629c4.stderr",
11-
"stderr_hash": "75e4a7ee6e09c7fa5b22705531b37c4cecc5e1294a7180b11613c9fc",
11+
"stderr_hash": "29aa01d7370a20ada91bdb13c569434f36a0c18309700d946d89fbf0",
1212
"returncode": 2
1313
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
semantic error: Type mismatch in index, expected a single integer
1+
semantic error: Type mismatch in index, expected a single integer or slice
22
--> tests/errors/string_01.py:3:13
33
|
44
3 | print(x[2, 5])
5-
| ^^^^ type mismatch (found: 'tuple[i32, i32]', expected: 'i32')
5+
| ^^^^ type mismatch (found: 'tuple[i32, i32]', expected: 'i32' or slice)

tests/reference/asr-test_list4-d18a7e3.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"stdout": null,
99
"stdout_hash": null,
1010
"stderr": "asr-test_list4-d18a7e3.stderr",
11-
"stderr_hash": "ca321da7e384252fb05ae20cc0112f5b981b66a4c77a94d0901fa96f",
11+
"stderr_hash": "98922e9f57ab8e9d7af05424e9fdb93a9a1722114f5abb816439b161",
1212
"returncode": 2
1313
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
semantic error: Type mismatch in index, expected a single integer
1+
semantic error: Type mismatch in index, expected a single integer or slice
22
--> tests/errors/test_list4.py:7:11
33
|
44
7 | x = a[0.2]
5-
| ^^^ type mismatch (found: 'f64', expected: 'i32')
5+
| ^^^ type mismatch (found: 'f64', expected: 'i32' or slice)

tests/reference/asr-test_str_indexing-b200a4e.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"stdout": null,
99
"stdout_hash": null,
1010
"stderr": "asr-test_str_indexing-b200a4e.stderr",
11-
"stderr_hash": "9dbdff50d35cb32f87924521b46535a68d8b1f45ac845161a263ea05",
11+
"stderr_hash": "eddc45a6ba83dc10551fd9685b6ea1096828ae29f6b9cce07cfe5de1",
1212
"returncode": 2
1313
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
semantic error: Type mismatch in index, expected a single integer
1+
semantic error: Type mismatch in index, expected a single integer or slice
22
--> tests/errors/test_str_indexing.py:4:13
33
|
44
4 | print(s[1.2])
5-
| ^^^ type mismatch (found: 'f64', expected: 'i32')
5+
| ^^^ type mismatch (found: 'f64', expected: 'i32' or slice)

0 commit comments

Comments
 (0)