Skip to content

Commit 575fcd0

Browse files
committed
Register the annassign type mismatch error
1 parent 1c1028d commit 575fcd0

5 files changed

+30
-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
@@ -1741,7 +1741,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
17411741
std::string ltype = ASRUtils::type_to_str(type);
17421742
std::string rtype = ASRUtils::type_to_str(ASRUtils::expr_type(value));
17431743
diag.add(diag::Diagnostic(
1744-
"Type mismatch for an annotation-assignment. In LPython, the types must be compatible.",
1744+
"Type mismatch in annotation-assignment, the types must be compatible",
17451745
diag::Level::Error, diag::Stage::Semantic, {
17461746
diag::Label("type mismatch (" + ltype + " and " + rtype + ")",
17471747
{x.m_target->base.loc, value->base.loc})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from ltypes import i32
2+
3+
def f():
4+
x: i32[4] = [1, 2, 3, 4]
5+
print(a)
6+
7+
f()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "asr-test_annassign_type_mismatch-7dac7be",
3+
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
4+
"infile": "tests/errors/test_annassign_type_mismatch.py",
5+
"infile_hash": "5dacc11ffb3bc47fb14e508f454836ce4b196598d1943237cba9c86c",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": null,
9+
"stdout_hash": null,
10+
"stderr": "asr-test_annassign_type_mismatch-7dac7be.stderr",
11+
"stderr_hash": "26b687e0b4a187c139b077ec970580df391288fce1d13bde3770ce3b",
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 in annotation-assignment, the types must be compatible
2+
--> tests/errors/test_annassign_type_mismatch.py:4:5
3+
|
4+
4 | x: i32[4] = [1, 2, 3, 4]
5+
| ^ ^^^^^^^^^^^^ type mismatch (integer and list)

tests/tests.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ asr = true
254254
filename = "errors/test_str_slicing.py"
255255
asr = true
256256

257+
[[test]]
258+
filename = "errors/test_annassign_type_mismatch.py"
259+
asr = true
260+
257261
[[test]]
258262
filename = "errors/test_append_type_mismatch.py"
259263
asr = true

0 commit comments

Comments
 (0)