analysis: add check for call expr's arguments
This commit is contained in:
parent
3f94082477
commit
4346636cfa
|
@ -42,6 +42,11 @@ fn multwo(num: i32, double_flag: bool) i32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn multwo_with_one(b: i32) i32 {
|
||||||
|
// TODO replace by b
|
||||||
|
return multwo(2, false) + 2;
|
||||||
|
}
|
||||||
|
|
||||||
fn add(a: i32, b: i32) i32 {
|
fn add(a: i32, b: i32) i32 {
|
||||||
return 69 + 69;
|
return 69 + 69;
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,7 +200,6 @@ pub const TypeSolver = struct {
|
||||||
// all numeric operations return numeric types
|
// all numeric operations return numeric types
|
||||||
.Add, .Sub, .Mul, .Div, .Mod => left_type,
|
.Add, .Sub, .Mul, .Div, .Mod => left_type,
|
||||||
|
|
||||||
// TODO check left and right as numeric
|
|
||||||
.Greater, .GreaterEqual, .Less, .LessEqual => blk: {
|
.Greater, .GreaterEqual, .Less, .LessEqual => blk: {
|
||||||
try self.expectSymUnTypeNumeric(left_type);
|
try self.expectSymUnTypeNumeric(left_type);
|
||||||
try self.expectSymUnTypeNumeric(right_type);
|
try self.expectSymUnTypeNumeric(right_type);
|
||||||
|
@ -226,7 +225,8 @@ pub const TypeSolver = struct {
|
||||||
return switch (literal) {
|
return switch (literal) {
|
||||||
.Bool => SymbolUnderlyingType{ .Bool = {} },
|
.Bool => SymbolUnderlyingType{ .Bool = {} },
|
||||||
|
|
||||||
// TODO determine its i64 depending of parseInt results
|
// TODO recast Integer32 as Integer64 if the type we're
|
||||||
|
// checking into is Integer64, but not the other way.
|
||||||
.Integer32 => SymbolUnderlyingType{ .Integer32 = {} },
|
.Integer32 => SymbolUnderlyingType{ .Integer32 = {} },
|
||||||
.Integer64 => SymbolUnderlyingType{ .Integer64 = {} },
|
.Integer64 => SymbolUnderlyingType{ .Integer64 = {} },
|
||||||
.Float => SymbolUnderlyingType{ .Double = {} },
|
.Float => SymbolUnderlyingType{ .Double = {} },
|
||||||
|
@ -256,8 +256,21 @@ pub const TypeSolver = struct {
|
||||||
var symbol = try ctx.fetchGlobalSymbol(func_name, .Function);
|
var symbol = try ctx.fetchGlobalSymbol(func_name, .Function);
|
||||||
var func_sym = symbol.Function;
|
var func_sym = symbol.Function;
|
||||||
|
|
||||||
// TODO check parameter type mismatches between
|
for (call.arguments.toSlice()) |arg_expr, idx| {
|
||||||
// call.arguments and func_sym.parameters
|
var param_type = func_sym.parameter_list.at(idx);
|
||||||
|
var arg_type = try self.resolveExprType(ctx, &arg_expr);
|
||||||
|
|
||||||
|
self.expectSymUnTypeEqual(arg_type, param_type) catch {
|
||||||
|
self.doError(
|
||||||
|
"Expected parameter {} to be {}, got {}",
|
||||||
|
idx,
|
||||||
|
@tagName(comp.SymbolUnderlyingTypeEnum(param_type)),
|
||||||
|
@tagName(comp.SymbolUnderlyingTypeEnum(arg_type)),
|
||||||
|
);
|
||||||
|
|
||||||
|
return CompileError.TypeError;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return func_sym.return_type;
|
return func_sym.return_type;
|
||||||
},
|
},
|
||||||
|
|
|
@ -76,6 +76,8 @@ pub const FunctionSymbol = struct {
|
||||||
/// Parameters for a function are also a table instead of an ArrayList
|
/// Parameters for a function are also a table instead of an ArrayList
|
||||||
/// because we want to resolve identifiers to them.
|
/// because we want to resolve identifiers to them.
|
||||||
parameters: UnderlyingTypeMap,
|
parameters: UnderlyingTypeMap,
|
||||||
|
parameter_list: TypeList,
|
||||||
|
|
||||||
scope: *Scope,
|
scope: *Scope,
|
||||||
|
|
||||||
/// Find a given identifier in the function. Can resolve to either a parameter
|
/// Find a given identifier in the function. Can resolve to either a parameter
|
||||||
|
@ -239,6 +241,7 @@ pub const CompilationContext = struct {
|
||||||
.decl = decl,
|
.decl = decl,
|
||||||
.return_type = ret_type,
|
.return_type = ret_type,
|
||||||
.parameters = type_map,
|
.parameters = type_map,
|
||||||
|
.parameter_list = param_types,
|
||||||
.scope = scope,
|
.scope = scope,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue