Skip to content

Commit

Permalink
Merge pull request #176 from nbuilding/bug-fix
Browse files Browse the repository at this point in the history
Fix what was going on with no argument functions
  • Loading branch information
SheepTester authored Jun 5, 2021
2 parents d1cc044 + 2e3199d commit c67f89c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
5 changes: 5 additions & 0 deletions python/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ def __init__(
):
# Tuples represent function types. (a, b, c) represents a -> b -> c.
types = tuple([ty for _, ty in arguments] + [returntype])
if len(arguments) == 0:
types = ("unit",) + (returntype,)

if isinstance(types[-1], tuple):
types = tuple([*types[0:-1], *types[-1]])
if None in types:
types = None
super(Function, self).__init__(types, self, public)
Expand Down
15 changes: 6 additions & 9 deletions python/run.n
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
class Test [i:int] {
let pub clone = [] -> Test {
return Test(i)
}

let pub uaua = [t:Test] -> Test {
return t.erererer()
let i: () -> () -> int = [] -> () -> int {
return [] -> int {
return 3
}
}

let t:Test = Test(10)
print(t.clone())
let ii: () -> int = i()

print(ii())
9 changes: 8 additions & 1 deletion python/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ async def eval_expr(self, expr):
arg_values = []
for arg in arguments:
arg_values.append(await self.eval_expr(arg))
if len(arg_values) == 0:
arg_values = [()]
return await (await self.eval_expr(function)).run(arg_values)
elif expr.data == "or_expression":
left, _, right = expr.children
Expand Down Expand Up @@ -1312,6 +1314,9 @@ def type_check_expr(self, expr):
mainarg = expr.children[0]
function, *arguments = expr.children[1].children
arguments.append(mainarg)

if len(arguments) == 0:
arguments.append("unit")
func_type = self.type_check_expr(function)
if func_type is None:
return None
Expand All @@ -1330,7 +1335,9 @@ def type_check_expr(self, expr):
for n, (argument, arg_type) in enumerate(
zip(arguments, arg_types), start=1
):
check_type = self.type_check_expr(argument)
check_type = argument
if(argument != "unit"):
check_type = self.type_check_expr(check_type)
if check_type is None:
parameters_have_none = True
resolved_arg_type = apply_generics(arg_type, check_type, generics)
Expand Down

0 comments on commit c67f89c

Please sign in to comment.