Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added semantic error for float declaration. #2529

Merged
merged 4 commits into from
Feb 13, 2024
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
11 changes: 10 additions & 1 deletion src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,16 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
})
);
throw SemanticAbort();
} else {
} else if (var_annotation == "float") {
std::string msg = "Hint: Use f32 or f64 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("The type '" + var_annotation+"' is undeclared.", loc);
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/errors/test_float_semantic_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from lpython import f64

def main0():
pi: float = 3.14
radi: f64 = 2.0
print("Area of Circle is", pi*radi**2)

main0()
13 changes: 13 additions & 0 deletions tests/reference/asr-test_float_semantic_error-58c0c90.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-test_float_semantic_error-58c0c90",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/test_float_semantic_error.py",
"infile_hash": "10929e3991a4aee1a2de473fc5f8caa48b6dcf4a35e2329a15ea5f1f",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-test_float_semantic_error-58c0c90.stderr",
"stderr_hash": "c11166fb86be513e74796a51f5c9e84653c2eb894ed95d502ed8af57",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-test_float_semantic_error-58c0c90.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: float type is not supported yet.
--> tests/errors/test_float_semantic_error.py:4:9
|
4 | pi: float = 3.14
| ^^^^^ Hint: Use f32 or f64 for now.
4 changes: 4 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,10 @@ asr = true
filename = "errors/test_int_semantic_error.py"
asr = true

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

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