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:
parent
7fd08eca96
commit
3bfad1b943
@ -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
|
||||
|
29
vlib/v/tests/generics_struct_inst_method_call_test.v
Normal file
29
vlib/v/tests/generics_struct_inst_method_call_test.v
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user