mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix code generation for array.clear (#18792)
This commit is contained in:
parent
11f06e41c0
commit
de392003be
@ -1281,7 +1281,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
|
||||
receiver_type_name = 'map'
|
||||
}
|
||||
if final_left_sym.kind == .array && !(left_sym.kind == .alias && left_sym.has_method(node.name))
|
||||
&& node.name in ['repeat', 'sort_with_compare', 'free', 'push_many', 'trim', 'first', 'last', 'pop', 'clone', 'reverse', 'slice', 'pointers'] {
|
||||
&& node.name in ['clear', 'repeat', 'sort_with_compare', 'free', 'push_many', 'trim', 'first', 'last', 'pop', 'clone', 'reverse', 'slice', 'pointers'] {
|
||||
if !(left_sym.info is ast.Alias && typ_sym.has_method(node.name)) {
|
||||
// `array_Xyz_clone` => `array_clone`
|
||||
receiver_type_name = 'array'
|
||||
|
29
vlib/v/tests/array_clear_test.v
Normal file
29
vlib/v/tests/array_clear_test.v
Normal file
@ -0,0 +1,29 @@
|
||||
struct Registry[T] {
|
||||
mut:
|
||||
events []EventHandler[T]
|
||||
}
|
||||
|
||||
struct EventHandler[T] {
|
||||
name T
|
||||
}
|
||||
|
||||
fn (mut r Registry[T]) test() {
|
||||
mut events := []EventHandler[string]{}
|
||||
r.events << EventHandler[string]{
|
||||
name: 'test'
|
||||
}
|
||||
assert 1 == r.events.len
|
||||
|
||||
r.events.clear()
|
||||
events.clear()
|
||||
|
||||
assert events.len == r.events.len
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
mut registry := &Registry[string]{
|
||||
events: []
|
||||
}
|
||||
registry.test()
|
||||
assert dump(registry.events).len == 0
|
||||
}
|
Loading…
Reference in New Issue
Block a user