diff --git a/examples/hello.ry b/examples/hello.ry index fb0d673..2942d87 100644 --- a/examples/hello.ry +++ b/examples/hello.ry @@ -1,7 +1,11 @@ // import std; +fn f() i32 { + return 2; +} + const ( - AWOO = 1 + 2 + piss = f() + 3 ) enum B { diff --git a/src/types.zig b/src/types.zig index f89d728..f170223 100644 --- a/src/types.zig +++ b/src/types.zig @@ -88,6 +88,8 @@ pub const TypeSolver = struct { } } + // TODO make return type optional and so, skip exprs that + // fail to be fully resolved, instead of returning CompileError pub fn resolveExprType( self: *@This(), ctx: *comp.CompilationContext, @@ -143,6 +145,26 @@ pub const TypeSolver = struct { return typ.?; }, + .Call => |call| { + self.setErrToken(call.paren); + std.debug.assert(ast.ExprType(call.callee.*) == .Variable); + const func_name = call.callee.*.Variable.lexeme; + + var sym_kv = ctx.symbol_table.get(func_name); + if (sym_kv == null) { + self.doError("Unknown function '{}'\n", func_name); + return CompileError.TypeError; + } + + std.debug.assert(comp.SymbolType(sym_kv.?.value) == .Function); + var func_sym = sym_kv.?.value.Function; + + // TODO check parameter type mismatches between + // call.arguments and func_sym.parameters + + return func_sym.return_type; + }, + // TODO variable resolution // TODO Get (for structs and enums)