Skip to content

Commit

Permalink
enhance check
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Aug 18, 2024
1 parent d639a4b commit 1a8e9bb
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions vlib/v/checker/infix.v
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,30 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
}
}

if node.left.is_nil() && !right_type.is_any_kind_of_pointer()
&& (right_final_sym.kind != .function
|| (right_final_sym.language != .c && right_final_sym.kind == .placeholder)) {
rt := c.table.sym(right_type).name
c.error('cannot compare with `nil` because `${rt}` is not a pointer',
node.pos)
if node.left.is_nil() {
mut final_type := right_type
if mut right_sym.info is ast.Alias {
final_type = right_sym.info.parent_type
}
if !final_type.is_any_kind_of_pointer() && (right_final_sym.kind != .function
|| (right_final_sym.language != .c && right_final_sym.kind == .placeholder)) {
rt := c.table.sym(right_type).name
c.error('cannot compare with `nil` because `${rt}` is not a pointer',
node.pos)
}
}

if node.right.is_nil() && !left_type.is_any_kind_of_pointer()
&& (left_final_sym.kind != .function
|| (left_final_sym.language != .c && left_final_sym.kind == .placeholder)) {
lt := c.table.sym(left_type).name
c.error('cannot compare with `nil` because `${lt}` is not a pointer',
node.pos)
if node.right.is_nil() {
mut final_type := left_type
if mut right_sym.info is ast.Alias {
final_type = right_sym.info.parent_type
}
if !final_type.is_any_kind_of_pointer() && (left_final_sym.kind != .function
|| (left_final_sym.language != .c && left_final_sym.kind == .placeholder)) {
lt := c.table.sym(left_type).name
c.error('cannot compare with `nil` because `${lt}` is not a pointer',
node.pos)
}
}
}
.key_in, .not_in {
Expand Down

0 comments on commit 1a8e9bb

Please sign in to comment.