Skip to content

Commit 0f4dc32

Browse files
ujjwaltwitxcertik
authored andcommitted
Added appropriate throw block for error and added test for async implementation
1 parent 6737a06 commit 0f4dc32

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4051,15 +4051,16 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
40514051
// Implement visit_Global for Symbol Table visitor.
40524052
void visit_Global(const AST::Global_t &/*x*/) {}
40534053

4054-
void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &/*x*/){
4054+
void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &x){
40554055
try
40564056
{
40574057
// to be implemented
40584058
}
40594059
catch(const std::exception& e)
40604060
{
40614061
std::cerr << e.what() << '\n';
4062-
}
4062+
}
4063+
throw SemanticError("The `async` keyword is currently not supported", x.base.base.loc);
40634064
}
40644065

40654066
void visit_FunctionDef(const AST::FunctionDef_t &x) {

tests/errors/test_async.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
async def test_async():
2+
print("done")
3+
4+
test_async()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "asr-test_async-361297c",
3+
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
4+
"infile": "tests/errors/test_async.py",
5+
"infile_hash": "f4d737246effd50f1798a81f07042ad15a045e275448fe0226334f03",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": null,
9+
"stdout_hash": null,
10+
"stderr": "asr-test_async-361297c.stderr",
11+
"stderr_hash": "abf614594f89a7a6d93d469d512e31de5adc64feef866957de80cd03",
12+
"returncode": 2
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
semantic error: The `async` keyword is currently not supported
2+
--> tests/errors/test_async.py:1:1 - 2:17
3+
|
4+
1 | async def test_async():
5+
| ^^^^^^^^^^^^^^^^^^^^^^^...
6+
...
7+
|
8+
2 | print("done")
9+
| ...^^^^^^^^^^^^^^^^^

tests/tests.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,10 @@ ast_new = true
784784

785785
# tests/errors
786786

787+
[[test]]
788+
filename = "errors/test_async.py"
789+
asr = true
790+
787791
[[test]]
788792
filename = "errors/test_str_indexing.py"
789793
asr = true

0 commit comments

Comments
 (0)