Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Sep 25, 2024
1 parent 41e045c commit 9d76c4c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 16 additions & 0 deletions vlib/v/checker/infix.v
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
c.error('left operand to `${node.op}` does not match the array element type: ${err.msg()}',
left_right_pos)
}
if mut node.right is ast.ArrayInit {
c.check_duplicated_items(node.right)
}
} else {
if mut node.right is ast.ArrayInit {
for i, typ in node.right.expr_types {
Expand Down Expand Up @@ -953,6 +956,19 @@ fn (mut c Checker) check_div_mod_by_zero(expr ast.Expr, op_kind token.Kind) {
}
}

fn (mut c Checker) check_duplicated_items(node &ast.ArrayInit) {
mut unique_items := []string{}
for item in node.exprs {
item_str := item.str()
// println('>>> ${item_str}')
if item.str() !in unique_items {
unique_items << item_str
} else {
c.error('the item `${item_str}` is duplicated in the list', item.pos())
}
}
}

fn (mut c Checker) check_like_operator(node &ast.InfixExpr) ast.Type {
if node.left !is ast.Ident || !node.left_type.is_string() {
c.error('the left operand of the `like` operator must be an identifier with a string type',
Expand Down
3 changes: 1 addition & 2 deletions vlib/v/checker/str.v
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) ast.Type {
}
if ((typ.is_unsigned() && fmt !in [`u`, `x`, `X`, `o`, `c`, `b`])
|| (typ.is_signed() && fmt !in [`d`, `x`, `X`, `o`, `c`, `b`])
|| (typ.is_int_literal()
&& fmt !in [`d`, `c`, `x`, `X`, `o`, `u`, `x`, `X`, `o`, `b`])
|| (typ.is_int_literal() && fmt !in [`d`, `c`, `x`, `X`, `o`, `u`, `b`])
|| (typ.is_float() && fmt !in [`E`, `F`, `G`, `e`, `f`, `g`])
|| (typ.is_pointer() && fmt !in [`p`, `x`, `X`])
|| (typ.is_string() && fmt !in [`s`, `S`, `r`, `R`])
Expand Down

0 comments on commit 9d76c4c

Please sign in to comment.