cgen: fix alias of array method call(fix #19125) (#19129)

This commit is contained in:
shove 2023-08-13 18:24:56 +08:00 committed by GitHub
parent f7187a7816
commit a711e17f41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -1436,8 +1436,13 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
arg_name := '_arg_expr_${fn_name}_0_${node.pos.pos}' arg_name := '_arg_expr_${fn_name}_0_${node.pos.pos}'
g.write('/*af receiver arg*/' + arg_name) g.write('/*af receiver arg*/' + arg_name)
} else { } else {
if left_sym.kind == .array && node.left.is_auto_deref_var() mut is_array := left_sym.kind == .array
&& is_array_method_first_last_repeat { if !is_array && left_sym.kind == .alias {
unaliased_type := g.table.unaliased_type(left_type)
unaliased_sym := g.table.sym(unaliased_type)
is_array = unaliased_sym.kind == .array
}
if is_array && node.left.is_auto_deref_var() && is_array_method_first_last_repeat {
g.write('*') g.write('*')
} }
if node.left is ast.MapInit { if node.left is ast.MapInit {

View File

@ -0,0 +1 @@
&Option(Element{})

View File

@ -0,0 +1,20 @@
struct Element {}
type ElementStack = []&Element
fn (mut stack ElementStack) pop_front() ?&Element {
return if stack.len > 0 {
val := stack.first()
stack.delete(0)
val
} else {
none
}
}
fn main() {
mut stack := ElementStack([]&Element{})
stack << &Element{}
a := stack.pop_front()
println(a)
}