1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix method call errors for generic struct instances (#13261)

This commit is contained in:
yuyi 2022-01-24 18:45:19 +08:00 committed by GitHub
parent 7fd08eca96
commit 3bfad1b943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View File

@ -1369,6 +1369,13 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
node.concrete_list_pos)
}
if method.generic_names.len > 0 {
if !left_type.has_flag(.generic) {
if left_sym.info is ast.Struct {
if method.generic_names.len == left_sym.info.concrete_types.len {
node.concrete_types = left_sym.info.concrete_types
}
}
}
return node.return_type
}
return method.return_type

View File

@ -0,0 +1,29 @@
fn test_generics_struct_inst_method_call() {
v1 := V2d<f32>{100}
r1 := v1.in_bounds(tp_lft, bt_rigt)
println(r1)
assert r1
}
const (
tp_lft = V2d<f32>{20}
bt_rigt = V2d<f32>{650}
)
struct V2d<T> {
mut:
x T
}
pub fn (v1 V2d<T>) unpack() T {
return v1.x
}
pub fn (v1 V2d<T>) less_than(v2 V2d<T>) V2d<bool> {
return V2d<bool>{v1.x < v2.x}
}
pub fn (v1 V2d<T>) in_bounds(top_left V2d<T>, bottom_right V2d<T>) bool {
v1.less_than(bottom_right).unpack()
return true
}