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

gen: blank identifier fixes

This commit is contained in:
Joe Conigliaro 2020-03-18 10:41:04 +11:00
parent 330745da30
commit 6ca47aeb4b

View File

@ -401,23 +401,13 @@ fn (g mut Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
ident_var_info := ident.var_info()
styp := g.typ(ident_var_info.typ)
if ident.kind == .blank_ident {
is_call := match val {
ast.CallExpr{
true
}
ast.MethodCallExpr{
true
}
else {
false}
}
if is_call {
if is_call(val) {
g.expr(val)
}
else {
g.write('{$styp _ = ')
g.expr(val)
g.write('}')
g.writeln('}')
}
}
else {
@ -572,6 +562,17 @@ fn (g mut Gen) expr(node ast.Expr) {
g.write('/* as */')
}
ast.AssignExpr {
if is_blank_ident(it.left) {
if is_call(it.val) {
g.expr(it.val)
}
else {
g.write('{${g.typ(it.left_type)} _ = ')
g.expr(it.val)
g.writeln('}')
}
}
else {
g.is_assign_expr = true
mut str_add := false
if it.left_type == table.string_type_idx && it.op == .plus_assign {
@ -598,6 +599,7 @@ fn (g mut Gen) expr(node ast.Expr) {
g.write(')')
}
}
}
ast.Assoc {
g.write('/* assoc */')
}
@ -1333,6 +1335,33 @@ fn (g mut Gen) ref_or_deref_arg(arg ast.CallArg) {
}
}
[inline]
fn is_blank_ident(expr ast.Expr) bool {
match expr {
ast.Ident {
return it.kind == .blank_ident
}
else {
return false
}
}
}
[inline]
fn is_call(expr ast.Expr) bool {
return match expr {
ast.CallExpr {
true
}
ast.MethodCallExpr {
true
}
else {
false
}
}
}
fn verror(s string) {
println('cgen error: $s')
// exit(1)