1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix error for array_of_aliases.pop() (#14861)

This commit is contained in:
yuyi 2022-06-27 16:50:46 +08:00 committed by GitHub
parent 34517c340d
commit 1af94c7edf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -1165,8 +1165,7 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
c.error('cannot $method_name `$arg_sym.name` to `$left_sym.name`', arg_expr.pos())
}
} else if final_left_sym.info is ast.Array && method_name in ['first', 'last', 'pop'] {
node.return_type = final_left_sym.info.elem_type
return node.return_type
return c.array_builtin_method_call(mut node, left_type, final_left_sym)
} else if c.pref.backend.is_js() && left_sym.name.starts_with('Promise<')
&& method_name == 'wait' {
info := left_sym.info as ast.Struct

View File

@ -0,0 +1,17 @@
[heap]
struct Attribute {
mut:
name string
value string
}
type AttributeStack = []&Attribute
fn test_array_of_alias_pop() {
mut stack := AttributeStack([]&Attribute{})
stack << &Attribute{'foo', 'bar'}
ret := stack.pop()
println(ret)
assert ret.name == 'foo'
assert ret.value == 'bar'
}