parser: add v error if assigning var to blank identifier `_`
also fix C warn & double semicolonpull/2180/head
parent
b7d1a175a8
commit
7fd2ef975b
|
@ -71,8 +71,15 @@ fn (p mut Parser) gen_fn_decl(f Fn, typ, str_args string) {
|
|||
|
||||
// blank identifer assignment `_ = 111`
|
||||
fn (p mut Parser) gen_blank_identifier_assign() {
|
||||
assign_error_tok_idx := p.token_idx
|
||||
p.check_name()
|
||||
p.check_space(.assign)
|
||||
expr := p.lit
|
||||
is_indexer := p.peek() == .lsbr
|
||||
is_fn_call := p.peek() == .lpar || (p.peek() == .dot && p.tokens[p.token_idx+2].tok == .lpar)
|
||||
if !is_indexer && !is_fn_call {
|
||||
p.error_with_token_index('assigning `$expr` to `_` is redundant', assign_error_tok_idx)
|
||||
}
|
||||
pos := p.cgen.add_placeholder()
|
||||
mut typ := p.bool_expression()
|
||||
tmp := p.get_tmp()
|
||||
|
@ -93,8 +100,13 @@ fn (p mut Parser) gen_blank_identifier_assign() {
|
|||
p.genln('string err = $tmp . error;')
|
||||
p.statements()
|
||||
p.returns = false
|
||||
}
|
||||
} else {
|
||||
if is_fn_call {
|
||||
p.gen(';')
|
||||
} else {
|
||||
p.cgen.resetln('{$typ _ = $p.cgen.cur_line;}')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn types_to_c(types []Type, table &Table) string {
|
||||
|
|
|
@ -35,8 +35,15 @@ fn (p mut Parser) gen_fn_decl(f Fn, typ, _str_args string) {
|
|||
}
|
||||
|
||||
fn (p mut Parser) gen_blank_identifier_assign() {
|
||||
assign_error_tok_idx := p.token_idx
|
||||
p.check_name()
|
||||
p.check_space(.assign)
|
||||
expr := p.lit
|
||||
is_indexer := p.peek() == .lsbr
|
||||
is_fn_call := p.peek() == .lpar || (p.peek() == .dot && p.tokens[p.token_idx+2].tok == .lpar)
|
||||
if !is_indexer && !is_fn_call {
|
||||
p.error_with_token_index('assigning `$expr` to `_` is redundant', assign_error_tok_idx)
|
||||
}
|
||||
p.bool_expression()
|
||||
or_else := p.tok == .key_orelse
|
||||
//tmp := p.get_tmp()
|
||||
|
|
|
@ -18,7 +18,6 @@ pub:
|
|||
|
||||
// Private function, used by V (`nums := []int`)
|
||||
fn new_array(mylen, cap, elm_size int) array {
|
||||
//println(a)
|
||||
arr := array {
|
||||
len: mylen
|
||||
cap: cap
|
||||
|
|
Loading…
Reference in New Issue