cgen: fix alias of array that has builtin method (#14432)

master
yuyi 2022-05-17 17:26:26 +08:00 committed by GitHub
parent d7b1e57186
commit 020845f6c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -941,7 +941,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
if left_sym.kind == .map && node.name in ['clone', 'move'] {
receiver_type_name = 'map'
}
if final_left_sym.kind == .array
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'] {
if !(left_sym.info is ast.Alias && typ_sym.has_method(node.name)) {
// `array_Xyz_clone` => `array_clone`

View File

@ -0,0 +1,11 @@
type Alias = []int
fn (a Alias) last() int {
return 22
}
fn test_alias_array_has_method() {
ret := Alias([0]).last()
println(ret)
assert ret == 22
}