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

cgen: fix array.last()

This commit is contained in:
Alexander Medvednikov 2020-03-19 08:49:47 +01:00
parent 3e70e5f2f1
commit 013fd5abfe
2 changed files with 5 additions and 2 deletions

View File

@ -748,7 +748,9 @@ fn (g mut Gen) expr(node ast.Expr) {
mut receiver_name := typ_sym.name mut receiver_name := typ_sym.name
if typ_sym.kind == .array && it.name in if typ_sym.kind == .array && it.name in
// TODO performance, detect `array` method differently // TODO performance, detect `array` method differently
['repeat', 'sort_with_compare', 'free', 'push_many', 'trim', 'first', 'clone'] { ['repeat', 'sort_with_compare', 'free', 'push_many', 'trim',
//
'first', 'last', 'clone'] {
// && rec_sym.name == 'array' { // && rec_sym.name == 'array' {
// && rec_sym.name == 'array' && receiver_name.starts_with('array') { // && rec_sym.name == 'array' && receiver_name.starts_with('array') {
// `array_byte_clone` => `array_clone` // `array_byte_clone` => `array_clone`
@ -1367,10 +1369,10 @@ fn (g mut Gen) const_decl(node ast.ConstDecl) {
// { user | name: 'new name' } // { user | name: 'new name' }
fn (g mut Gen) assoc(node ast.Assoc) { fn (g mut Gen) assoc(node ast.Assoc) {
g.writeln('// assoc')
if node.typ == 0 { if node.typ == 0 {
return return
} }
g.writeln('// assoc')
styp := g.typ(node.typ) styp := g.typ(node.typ)
g.writeln('($styp){') g.writeln('($styp){')
for i, field in node.fields { for i, field in node.fields {

View File

@ -794,6 +794,7 @@ pub fn (p mut Parser) expr(precedence int) ast.Expr {
p.error('unknown variable `$name`') p.error('unknown variable `$name`')
return node return node
} }
println('assoc var $name typ=$var.typ')
mut fields := []string mut fields := []string
mut vals := []ast.Expr mut vals := []ast.Expr
p.check(.pipe) p.check(.pipe)