1
0
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:
Felipe Pena 2023-07-06 18:28:06 -03:00 committed by GitHub
parent 11f06e41c0
commit de392003be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -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'

View 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
}