Skip to content

Commit edbe3c2

Browse files
committed
Add a test for overloading
1 parent b775044 commit edbe3c2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

integration_tests/test_generics_01.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from ltypes import overload
2+
3+
@overload
4+
def foo(a: int, b: int) -> int:
5+
return a*b
6+
7+
@overload
8+
def foo(a: int) -> int:
9+
return a**2
10+
11+
@overload
12+
def foo(a: str) -> str:
13+
return "lpython-" + a
14+
15+
@overload
16+
def test(a: int) -> int:
17+
return a + 10
18+
19+
@overload
20+
def test(a: bool) -> int:
21+
if a:
22+
return 10
23+
return -10
24+
25+
26+
assert foo(2) == 4
27+
assert foo(2, 10) == 20
28+
assert foo("hello") == "lpython-hello"
29+
assert test(10) == 20
30+
assert test(False) == -test(True) and test(True) == 10

0 commit comments

Comments
 (0)