add rudimentary return type analysis for call exprs
This commit is contained in:
parent
04c624e210
commit
5036be02e3
2 changed files with 27 additions and 1 deletions
|
@ -1,7 +1,11 @@
|
||||||
// import std;
|
// import std;
|
||||||
|
|
||||||
|
fn f() i32 {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AWOO = 1 + 2
|
piss = f() + 3
|
||||||
)
|
)
|
||||||
|
|
||||||
enum B {
|
enum B {
|
||||||
|
|
|
@ -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(
|
pub fn resolveExprType(
|
||||||
self: *@This(),
|
self: *@This(),
|
||||||
ctx: *comp.CompilationContext,
|
ctx: *comp.CompilationContext,
|
||||||
|
@ -143,6 +145,26 @@ pub const TypeSolver = struct {
|
||||||
return typ.?;
|
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 variable resolution
|
||||||
|
|
||||||
// TODO Get (for structs and enums)
|
// TODO Get (for structs and enums)
|
||||||
|
|
Loading…
Reference in a new issue