Skip to content

Commit

Permalink
Added appropriate throw block for error and added test for async impl…
Browse files Browse the repository at this point in the history
…ementation
  • Loading branch information
ujjwaltwitx committed Dec 13, 2023
1 parent 86f0db5 commit 6e271d8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4051,15 +4051,16 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
// Implement visit_Global for Symbol Table visitor.
void visit_Global(const AST::Global_t &/*x*/) {}

void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &/*x*/){
void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &x){
try
{
// to be implemented
}
catch(const std::exception& e)
{
std::cerr << e.what() << '\n';
}
}
throw SemanticError("The `async` keyword is currently not supported", x.base.base.loc);
}

void visit_FunctionDef(const AST::FunctionDef_t &x) {
Expand Down
4 changes: 4 additions & 0 deletions tests/errors/test_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
async def test_async():
print("done")

test_async()
13 changes: 13 additions & 0 deletions tests/reference/asr-test_async-361297c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-test_async-361297c",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/test_async.py",
"infile_hash": "f4d737246effd50f1798a81f07042ad15a045e275448fe0226334f03",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-test_async-361297c.stderr",
"stderr_hash": "abf614594f89a7a6d93d469d512e31de5adc64feef866957de80cd03",
"returncode": 2
}
9 changes: 9 additions & 0 deletions tests/reference/asr-test_async-361297c.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
semantic error: The `async` keyword is currently not supported
--> tests/errors/test_async.py:1:1 - 2:17
|
1 | async def test_async():
| ^^^^^^^^^^^^^^^^^^^^^^^...
...
|
2 | print("done")
| ...^^^^^^^^^^^^^^^^^
4 changes: 4 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,10 @@ ast_new = true

# tests/errors

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

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

0 comments on commit 6e271d8

Please sign in to comment.