Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,18 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
}

if( !type && raise_error ) {
throw SemanticError("Unsupported type annotation: " + var_annotation, loc);
if (var_annotation == "int") {
std::string msg = "Hint: Use i8, i16, i32 or i64 for now. ";
diag.add(diag::Diagnostic(
var_annotation + " type is not supported yet. ",
diag::Level::Error, diag::Stage::Semantic, {
diag::Label(msg, {loc})
})
);
throw SemanticAbort();
} else {
throw SemanticError("Unsupported type annotation: " + var_annotation, loc);
}
}

return type;
Expand Down
8 changes: 8 additions & 0 deletions tests/errors/test_int_semantic_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from lpython import i32

def variable_function():
x: int = 1
y: i32 = 2
print("x + y is", x + y)

variable_function()
13 changes: 13 additions & 0 deletions tests/reference/asr-test_int_semantic_error-44fe25e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-test_int_semantic_error-44fe25e",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/test_int_semantic_error.py",
"infile_hash": "79ca7d3f440b2538aa0819f910bea5ef24820d245b2179e1bf4cce6d",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-test_int_semantic_error-44fe25e.stderr",
"stderr_hash": "a1cd1ec0fee194e3c1651668753a1666ca46c925fa91335c6230e026",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-test_int_semantic_error-44fe25e.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: int type is not supported yet.
--> tests/errors/test_int_semantic_error.py:4:8
|
4 | x: int = 1
| ^^^ Hint: Use i8, i16, i32 or i64 for now.
4 changes: 4 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,10 @@ asr = true
filename = "errors/test_unsupported_type.py"
asr = true

[[test]]
filename = "errors/test_int_semantic_error.py"
asr = true

[[test]]
filename = "errors/generics_error_01.py"
asr = true
Expand Down