Skip to content

Commit bffa0a8

Browse files
authored
Merge pull request #411 from Smit-create/i-399
Fixes overload issue with subroutines
2 parents 2739a85 + 2b4ca11 commit bffa0a8

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

integration_tests/test_generics_01.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from overload_testing import foo, test
2-
from ltypes import overload, i32
2+
from ltypes import overload, i32, i64
33
import overload_testing2
44

5+
56
@overload
67
def foo1(a: i32, b: i32) -> i32:
78
return a-b
@@ -14,6 +15,7 @@ def foo1(a: i32) -> i32:
1415
def foo1(a: str) -> str:
1516
return "lpython-is-fun-" + a
1617

18+
1719
@overload
1820
def test1(a: i32) -> i32:
1921
return a + 20
@@ -25,6 +27,19 @@ def test1(a: bool) -> i32:
2527
return -20
2628

2729

30+
@overload
31+
def add(a: i32):
32+
print(a)
33+
34+
@overload
35+
def add(a: i32, b: i32):
36+
print(a + b)
37+
38+
@overload
39+
def add(a: i32, b: i64):
40+
print(a + b)
41+
42+
2843
def check():
2944
assert foo(2) == 4
3045
assert foo1(2) == 16
@@ -41,5 +56,11 @@ def check():
4156
assert test(False) == -test(True) and test(True) == 10
4257
assert test1(False) == -test1(True) and test1(True) == 20
4358
assert overload_testing2.test2(True) == 30
59+
# We are testing the subroutine using print to test it actually works
60+
add(1, 2)
61+
add(3)
62+
i: i64
63+
i = 10
64+
add(2, i)
4465

4566
check()

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,8 +2560,8 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
25602560
throw SemanticError("Function '" + call_name + "' is not declared",
25612561
x.base.base.loc);
25622562
}
2563-
tmp = ASR::make_SubroutineCall_t(al, x.base.base.loc, s,
2564-
nullptr, args.p, args.size(), nullptr);
2563+
tmp = make_call_helper(al, s, current_scope, args, call_name,
2564+
x.base.base.loc);
25652565
return;
25662566
}
25672567
this->visit_expr(*x.m_value);

0 commit comments

Comments
 (0)