Skip to content

Commit

Permalink
combines tests and add more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Jun 12, 2024
1 parent cac4fdc commit 1926dc8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion vlib/v/checker/infix.v
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
} else if right_sym.info is ast.Alias
&& c.table.sym(right_sym.info.parent_type).is_primitive() {
if right_sym.has_method(node.op.str()) {
if method := left_sym.find_method(node.op.str()) {
if method := right_sym.find_method(node.op.str()) {
return_type = method.return_type
}
}
Expand Down
40 changes: 40 additions & 0 deletions vlib/v/tests/alias_primitive_operator_overloading_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,45 @@ fn test_alias_primitive_operator_overloading() {
c := a + b
d := a.add(b)
assert typeof(c).name == 'Alias'
assert typeof(d).name == 'Alias'

e := a * b
f := a.mul(b)
assert typeof(c).name == 'Alias'
assert typeof(d).name == 'Alias'
}

type AF_ARRAY = voidptr

fn (a AF_ARRAY) add(b AF_ARRAY) AF_ARRAY {
mut y := AF_ARRAY(0)
return y
}

fn (a AF_ARRAY) mul(b AF_ARRAY) AF_ARRAY {
mut y := AF_ARRAY(0)
return y
}

fn (a AF_ARRAY) + (b AF_ARRAY) AF_ARRAY {
return a.add(b)
}

fn (a AF_ARRAY) * (b AF_ARRAY) AF_ARRAY {
return a.mul(b)
}

fn test_alias_voidptr_operator_overloading() {
a := AF_ARRAY(0)
b := AF_ARRAY(0)

c := a + b
y := a * a

assert c == a.add(b)
assert y == a.mul(a)

assert typeof(c).name == 'AF_ARRAY'
assert typeof(y).name == 'AF_ARRAY'
}

30 changes: 0 additions & 30 deletions vlib/v/tests/alias_voidptr_operator_overloading_test.v

This file was deleted.

0 comments on commit 1926dc8

Please sign in to comment.