mirror of
https://github.com/vlang/v.git
synced 2025-09-16 02:49:31 -04:00
This commit is contained in:
parent
f2cb462d26
commit
19a7fbcf28
@ -352,12 +352,24 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
||||
} else {
|
||||
return_type = right_type
|
||||
}
|
||||
} else if right_final_sym.has_method(node.op.str()) {
|
||||
if method := right_final_sym.find_method(node.op.str()) {
|
||||
} else if right_final_sym.has_method_with_generic_parent(node.op.str()) {
|
||||
if method := right_final_sym.find_method_with_generic_parent(node.op.str()) {
|
||||
return_type = method.return_type
|
||||
} else {
|
||||
return_type = right_type
|
||||
}
|
||||
} else if left_sym.has_method(node.op.str()) {
|
||||
if method := left_sym.find_method(node.op.str()) {
|
||||
return_type = method.return_type
|
||||
} else {
|
||||
return_type = left_type
|
||||
}
|
||||
} else if left_final_sym.has_method_with_generic_parent(node.op.str()) {
|
||||
if method := left_final_sym.find_method_with_generic_parent(node.op.str()) {
|
||||
return_type = method.return_type
|
||||
} else {
|
||||
return_type = left_type
|
||||
}
|
||||
} else {
|
||||
left_name := c.table.type_to_str(unwrapped_left_type)
|
||||
right_name := c.table.type_to_str(unwrapped_right_type)
|
||||
|
22
vlib/v/tests/aliases/alias_with_op_overloading_test.v
Normal file
22
vlib/v/tests/aliases/alias_with_op_overloading_test.v
Normal file
@ -0,0 +1,22 @@
|
||||
module main
|
||||
|
||||
import math.vec
|
||||
|
||||
type Vector3 = vec.Vec3[f32]
|
||||
|
||||
pub fn calc(a Vector3, b Vector3) Vector3 {
|
||||
f := a.normalize()
|
||||
return f * a + a * f
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
a := Vector3{
|
||||
x: 1
|
||||
y: 2
|
||||
z: 3
|
||||
}
|
||||
t := calc(a, a)
|
||||
assert int(t.x) == 0
|
||||
assert int(t.y) == 2
|
||||
assert int(t.z) == 4
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user