Skip to content

Error on simple type with output intent #1852

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

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
6 changes: 6 additions & 0 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3868,6 +3868,12 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
AST::expr_t* arg_annotation_type = get_var_intent_and_annotation(x.m_args.m_args[i].m_annotation, s_intent);
is_allocatable = false;
ASR::ttype_t *arg_type = ast_expr_to_asr_type(x.base.base.loc, *arg_annotation_type, is_allocatable);
if ((s_intent == ASRUtils::intent_inout || s_intent == ASRUtils::intent_out)
&& !ASRUtils::is_aggregate_type(arg_type)) {
throw SemanticError("Simple Type " + ASRUtils::type_to_str_python(arg_type)
+ " cannot be intent InOut/Out", loc);
}

// Set the function as generic if an argument is typed with a type parameter
if (ASRUtils::is_generic(*arg_type)) {
ASR::ttype_t* arg_type_type = ASRUtils::get_type_parameter(arg_type);
Expand Down
5 changes: 5 additions & 0 deletions tests/errors/func_02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from lpython import i32, In

def f(n: In[i32]):
n = 5
print(n)
4 changes: 4 additions & 0 deletions tests/errors/func_03.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from lpython import i32

def f(l: list[i32]):
l[5] = 5
4 changes: 4 additions & 0 deletions tests/errors/func_04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from lpython import i32

def f(l: list[i32]):
l[5] = 5
5 changes: 5 additions & 0 deletions tests/errors/func_05.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from lpython import i32, InOut

def f(n: InOut[i32]):
n = 5
print(n)
13 changes: 13 additions & 0 deletions tests/reference/asr-func_02-b439474.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-func_02-b439474",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/func_02.py",
"infile_hash": "452658f9bae7ccab4d21b9b1c993adb7fbaf117c093dd82672755aa5",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-func_02-b439474.stderr",
"stderr_hash": "51b7e0552f91115242b7c38f82c258b3d8dda88c9596ddee5388e0a1",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-func_02-b439474.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Assignment to an input function parameter `n` is not allowed
--> tests/errors/func_02.py:4:5
|
4 | n = 5
| ^
13 changes: 13 additions & 0 deletions tests/reference/asr-func_03-cd744a0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-func_03-cd744a0",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/func_03.py",
"infile_hash": "763216ad3cb1090dc322e63706d4f92be4e806b1fc2df6f160d02fd0",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-func_03-cd744a0.stderr",
"stderr_hash": "cdd453e23646de3ff697ffe6a99908520edb195d28871de63db5a430",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-func_03-cd744a0.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Assignment to an input function parameter `l` is not allowed
--> tests/errors/func_03.py:4:5
|
4 | l[5] = 5
| ^
13 changes: 13 additions & 0 deletions tests/reference/asr-func_04-eef2656.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-func_04-eef2656",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/func_04.py",
"infile_hash": "763216ad3cb1090dc322e63706d4f92be4e806b1fc2df6f160d02fd0",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-func_04-eef2656.stderr",
"stderr_hash": "c0ef482d68b30b03615927ecd02a30b14ff4d24b5673b7399671ee79",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-func_04-eef2656.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Assignment to an input function parameter `l` is not allowed
--> tests/errors/func_04.py:4:5
|
4 | l[5] = 5
| ^
13 changes: 13 additions & 0 deletions tests/reference/asr-func_05-c22b921.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-func_05-c22b921",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/func_05.py",
"infile_hash": "70a0b0ddad67252c7488d322ffc565a6669e1f79b96c3ef3014b0d0a",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-func_05-c22b921.stderr",
"stderr_hash": "9611beb75ae308f86e573592164c5aca50c4e1acec2e91e48687ba96",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-func_05-c22b921.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Simple Type i32 cannot be intent InOut/Out
--> tests/errors/func_05.py:3:7
|
3 | def f(n: InOut[i32]):
| ^^^^^^^^^^^^^
16 changes: 16 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,22 @@ asr = true
filename = "errors/func_01.py"
asr = true

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

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

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

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

# tests/runtime_errors
[[test]]
filename = "runtime_errors/test_list_01.py"
Expand Down