Skip to content

Commit

Permalink
cgen: c2v infix fix
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Jun 1, 2022
1 parent 84e375e commit c54c9b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/gen/c/cgen.v
Expand Up @@ -1825,7 +1825,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
g.global_decl(node)
}
ast.GotoLabel {
g.writeln('${c_name(node.name)}: {}')
g.writeln('${c_name(node.name)}: ')
}
ast.GotoStmt {
g.write_v_source_line_info(node.pos)
Expand Down
8 changes: 8 additions & 0 deletions vlib/v/gen/c/infix.v
Expand Up @@ -87,6 +87,10 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
right := g.unwrap(node.right_type)
has_defined_eq_operator := g.table.has_method(left.sym, '==')
has_alias_eq_op_overload := left.sym.info is ast.Alias && left.sym.has_method('==')
if g.pref.translated && !g.is_builtin_mod {
g.gen_plain_infix_expr(node)
return
}
if (left.typ.is_ptr() && right.typ.is_int()) || (right.typ.is_ptr() && left.typ.is_int()) {
g.gen_plain_infix_expr(node)
} else if (left.typ.idx() == ast.string_type_idx || (!has_defined_eq_operator
Expand Down Expand Up @@ -291,6 +295,10 @@ fn (mut g Gen) infix_expr_cmp_op(node ast.InfixExpr) {
left := g.unwrap(node.left_type)
right := g.unwrap(node.right_type)
has_operator_overloading := g.table.has_method(left.sym, '<')
if g.pref.translated && !g.is_builtin_mod {
g.gen_plain_infix_expr(node)
return
}
if left.sym.kind == .struct_ && (left.sym.info as ast.Struct).generic_types.len > 0 {
if node.op in [.le, .ge] {
g.write('!')
Expand Down

0 comments on commit c54c9b8

Please sign in to comment.