Skip to content

Commit 6285062

Browse files
authored
Merge pull request #2476 from NishantBansal2003/semantic_error_update
fixes semantic error for int (Issue #1926)
2 parents 8b1988d + a95716c commit 6285062

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,18 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
876876
}
877877

878878
if( !type && raise_error ) {
879-
throw SemanticError("Unsupported type annotation: " + var_annotation, loc);
879+
if (var_annotation == "int") {
880+
std::string msg = "Hint: Use i8, i16, i32 or i64 for now. ";
881+
diag.add(diag::Diagnostic(
882+
var_annotation + " type is not supported yet. ",
883+
diag::Level::Error, diag::Stage::Semantic, {
884+
diag::Label(msg, {loc})
885+
})
886+
);
887+
throw SemanticAbort();
888+
} else {
889+
throw SemanticError("Unsupported type annotation: " + var_annotation, loc);
890+
}
880891
}
881892

882893
return type;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from lpython import i32
2+
3+
def variable_function():
4+
x: int = 1
5+
y: i32 = 2
6+
print("x + y is", x + y)
7+
8+
variable_function()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "asr-test_int_semantic_error-44fe25e",
3+
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
4+
"infile": "tests/errors/test_int_semantic_error.py",
5+
"infile_hash": "79ca7d3f440b2538aa0819f910bea5ef24820d245b2179e1bf4cce6d",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": null,
9+
"stdout_hash": null,
10+
"stderr": "asr-test_int_semantic_error-44fe25e.stderr",
11+
"stderr_hash": "a1cd1ec0fee194e3c1651668753a1666ca46c925fa91335c6230e026",
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: int type is not supported yet.
2+
--> tests/errors/test_int_semantic_error.py:4:8
3+
|
4+
4 | x: int = 1
5+
| ^^^ Hint: Use i8, i16, i32 or i64 for now.

tests/tests.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,10 @@ asr = true
11001100
filename = "errors/test_unsupported_type.py"
11011101
asr = true
11021102

1103+
[[test]]
1104+
filename = "errors/test_int_semantic_error.py"
1105+
asr = true
1106+
11031107
[[test]]
11041108
filename = "errors/generics_error_01.py"
11051109
asr = true

0 commit comments

Comments
 (0)