fix: fix infering int and float literal in generic fn calls (#9287)
parent
c0779e8455
commit
db152868c0
|
@ -443,7 +443,7 @@ pub fn (mut c Checker) infer_fn_types(f table.Fn, mut call_expr ast.CallExpr) {
|
||||||
arg := call_expr.args[arg_i]
|
arg := call_expr.args[arg_i]
|
||||||
param_type_sym := c.table.get_type_symbol(param.typ)
|
param_type_sym := c.table.get_type_symbol(param.typ)
|
||||||
if param.typ.has_flag(.generic) && param_type_sym.name == gt_name {
|
if param.typ.has_flag(.generic) && param_type_sym.name == gt_name {
|
||||||
typ = arg.typ
|
typ = c.table.mktyp(arg.typ)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
arg_sym := c.table.get_type_symbol(arg.typ)
|
arg_sym := c.table.get_type_symbol(arg.typ)
|
||||||
|
|
|
@ -10,7 +10,7 @@ fn test_array() {
|
||||||
mut a := [7, 8]
|
mut a := [7, 8]
|
||||||
r := f_array(a)
|
r := f_array(a)
|
||||||
assert r == 7
|
assert r == 7
|
||||||
|
|
||||||
g_array(mut a)
|
g_array(mut a)
|
||||||
assert a[0] == 8
|
assert a[0] == 8
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,15 @@ fn test_explicit_calls_should_also_work() {
|
||||||
assert true
|
assert true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_type_name<T>(x T) string {
|
||||||
|
return T.name
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_literal() {
|
||||||
|
assert get_type_name(1) == 'int'
|
||||||
|
assert get_type_name(1.0) == 'f64'
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
fn choose4<T>(a T, b T, c T, d T) T {
|
fn choose4<T>(a T, b T, c T, d T) T {
|
||||||
// NB: a similar construct is used in prime31's via engine
|
// NB: a similar construct is used in prime31's via engine
|
||||||
|
|
Loading…
Reference in New Issue