parser: fix regression with blank identifier & decl assign
parent
c1eb714a7f
commit
89ea8a0275
|
@ -1432,10 +1432,10 @@ fn (p mut Parser) var_decl() {
|
||||||
mut var_names := [p.check_name()] // add first variable
|
mut var_names := [p.check_name()] // add first variable
|
||||||
|
|
||||||
p.scanner.validate_var_name(var_names[0])
|
p.scanner.validate_var_name(var_names[0])
|
||||||
// mut new_vars := 0
|
mut new_vars := 0
|
||||||
// if var_names[0] != '_' && !p.known_var(var_names[0]) {
|
if var_names[0] != '_' && !p.known_var(var_names[0]) {
|
||||||
// new_vars++
|
new_vars++
|
||||||
// }
|
}
|
||||||
// more than 1 vars (multiple returns)
|
// more than 1 vars (multiple returns)
|
||||||
for p.tok == .comma {
|
for p.tok == .comma {
|
||||||
p.check(.comma)
|
p.check(.comma)
|
||||||
|
@ -1448,9 +1448,9 @@ fn (p mut Parser) var_decl() {
|
||||||
var_token_idxs << p.cur_tok_index()
|
var_token_idxs << p.cur_tok_index()
|
||||||
var_name := p.check_name()
|
var_name := p.check_name()
|
||||||
p.scanner.validate_var_name(var_name)
|
p.scanner.validate_var_name(var_name)
|
||||||
// if var_name != '_' && !p.known_var(var_name) {
|
if var_name != '_' && !p.known_var(var_name) {
|
||||||
// new_vars++
|
new_vars++
|
||||||
// }
|
}
|
||||||
var_names << var_name
|
var_names << var_name
|
||||||
}
|
}
|
||||||
is_assign := p.tok == .assign
|
is_assign := p.tok == .assign
|
||||||
|
@ -1462,10 +1462,10 @@ fn (p mut Parser) var_decl() {
|
||||||
} else {
|
} else {
|
||||||
p.error('expected `=` or `:=`')
|
p.error('expected `=` or `:=`')
|
||||||
}
|
}
|
||||||
// all vars on left of `:=` already defined
|
// all vars on left of `:=` already defined (or `_`)
|
||||||
// if is_decl_assign && var_names.len > 1 && new_vars == 0 {
|
if is_decl_assign && /*var_names.len > 1 &&*/ new_vars == 0 {
|
||||||
// p.error_with_token_index('no new variables on left side of `:=`', var_token_idxs.last())
|
p.error_with_token_index('no new variables on left side of `:=`', var_token_idxs.last())
|
||||||
// }
|
}
|
||||||
p.var_decl_name = if var_names.len > 1 { '_V_mret_'+var_names.join('_') } else { var_names[0] }
|
p.var_decl_name = if var_names.len > 1 { '_V_mret_'+var_names.join('_') } else { var_names[0] }
|
||||||
t := p.gen_var_decl(p.var_decl_name, is_static)
|
t := p.gen_var_decl(p.var_decl_name, is_static)
|
||||||
mut var_types := [t]
|
mut var_types := [t]
|
||||||
|
@ -1480,12 +1480,15 @@ fn (p mut Parser) var_decl() {
|
||||||
}
|
}
|
||||||
for i, var_name in var_names {
|
for i, var_name in var_names {
|
||||||
var_token_idx := var_token_idxs[i]
|
var_token_idx := var_token_idxs[i]
|
||||||
if var_name == '_' {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var_is_mut := var_mut[i]
|
var_is_mut := var_mut[i]
|
||||||
var_type := var_types[i]
|
var_type := var_types[i]
|
||||||
known_var := p.known_var(var_name)
|
known_var := p.known_var(var_name)
|
||||||
|
if var_name == '_' {
|
||||||
|
if var_is_mut {
|
||||||
|
p.error_with_token_index('`mut` has no effect here', var_token_idx-1)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
// println('var decl tok=${p.strtok()} name=type=$var_name type=$var_type ismut=$var_is_mut')
|
// println('var decl tok=${p.strtok()} name=type=$var_name type=$var_type ismut=$var_is_mut')
|
||||||
// var decl, already exists (shadowing is not allowed)
|
// var decl, already exists (shadowing is not allowed)
|
||||||
// Don't allow declaring a variable with the same name. Even in a child scope
|
// Don't allow declaring a variable with the same name. Even in a child scope
|
||||||
|
|
Loading…
Reference in New Issue