Skip to content

Commit

Permalink
checker: allow generic operators to be called in fn (fix #23773) (#23774
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Delta456 authored Feb 21, 2025
1 parent 6d017f3 commit e613211
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions vlib/v/checker/infix.v
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
}
}
mut right_sym := c.table.sym(right_type)
right_final_sym := c.table.final_sym(right_type)
left_final_sym := c.table.final_sym(left_type)
right_final_sym := c.table.final_sym(c.unwrap_generic(right_type))
left_final_sym := c.table.final_sym(c.unwrap_generic(left_type))
left_pos := node.left.pos()
right_pos := node.right.pos()
left_right_pos := left_pos.extend(right_pos)
Expand Down
15 changes: 15 additions & 0 deletions vlib/v/tests/generics/generic_alias_fn_op_call_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module main

type MyAlias = f32

const two = MyAlias(2)

fn mul[T](a T, b T) T {
return a * b
}

fn test_generic_alias_fn_op_call() {
assert mul[MyAlias](two, two) == f32(4.0)
assert mul[f32](two, two) == f32(4.0)
assert two * two == f32(4.0)
}

0 comments on commit e613211

Please sign in to comment.