Skip to content

Fixes overload issue with subroutines #411

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
merged 2 commits into from
Apr 22, 2022
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
23 changes: 22 additions & 1 deletion integration_tests/test_generics_01.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from overload_testing import foo, test
from ltypes import overload, i32
from ltypes import overload, i32, i64
import overload_testing2


@overload
def foo1(a: i32, b: i32) -> i32:
return a-b
Expand All @@ -14,6 +15,7 @@ def foo1(a: i32) -> i32:
def foo1(a: str) -> str:
return "lpython-is-fun-" + a


@overload
def test1(a: i32) -> i32:
return a + 20
Expand All @@ -25,6 +27,19 @@ def test1(a: bool) -> i32:
return -20


@overload
def add(a: i32):
print(a)

@overload
def add(a: i32, b: i32):
print(a + b)

@overload
def add(a: i32, b: i64):
print(a + b)


def check():
assert foo(2) == 4
assert foo1(2) == 16
Expand All @@ -41,5 +56,11 @@ def check():
assert test(False) == -test(True) and test(True) == 10
assert test1(False) == -test1(True) and test1(True) == 20
assert overload_testing2.test2(True) == 30
# We are testing the subroutine using print to test it actually works
add(1, 2)
add(3)
i: i64
i = 10
add(2, i)

check()
4 changes: 2 additions & 2 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2560,8 +2560,8 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
throw SemanticError("Function '" + call_name + "' is not declared",
x.base.base.loc);
}
tmp = ASR::make_SubroutineCall_t(al, x.base.base.loc, s,
nullptr, args.p, args.size(), nullptr);
tmp = make_call_helper(al, s, current_scope, args, call_name,
x.base.base.loc);
return;
}
this->visit_expr(*x.m_value);
Expand Down