mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix generic array delete in skip_unused mode (#17759)
This commit is contained in:
parent
ca198ace7d
commit
a9f55de352
|
@ -25,7 +25,7 @@ const (
|
|||
|
||||
pub const (
|
||||
array_builtin_methods = ['filter', 'clone', 'repeat', 'reverse', 'map', 'slice', 'sort',
|
||||
'contains', 'index', 'wait', 'any', 'all', 'first', 'last', 'pop']
|
||||
'contains', 'index', 'wait', 'any', 'all', 'first', 'last', 'pop', 'delete']
|
||||
array_builtin_methods_chk = token.new_keywords_matcher_from_array_trie(array_builtin_methods)
|
||||
// TODO: remove `byte` from this list when it is no longer supported
|
||||
reserved_type_names = ['byte', 'bool', 'char', 'i8', 'i16', 'int', 'i64', 'u8', 'u16',
|
||||
|
|
|
@ -2426,6 +2426,11 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
|
|||
} else {
|
||||
node.receiver_type = left_type
|
||||
}
|
||||
} else if method_name == 'delete' {
|
||||
unwrapped_left_sym := c.table.sym(c.unwrap_generic(left_type))
|
||||
if method := c.table.find_method(unwrapped_left_sym, method_name) {
|
||||
node.receiver_type = method.receiver_type
|
||||
}
|
||||
}
|
||||
return node.return_type
|
||||
}
|
||||
|
|
16
vlib/v/tests/skip_unused/generics_array_delete_method.vv
Normal file
16
vlib/v/tests/skip_unused/generics_array_delete_method.vv
Normal file
|
@ -0,0 +1,16 @@
|
|||
struct Bar[K] {
|
||||
}
|
||||
|
||||
struct Foo[K] {
|
||||
mut:
|
||||
bars []Bar[K]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut f := Foo[int]{[Bar[int]{}]}
|
||||
f.xy()
|
||||
}
|
||||
|
||||
pub fn (mut f Foo[K]) xy() {
|
||||
f.bars.delete(0)
|
||||
}
|
Loading…
Reference in New Issue
Block a user