| 1 | import math |
| 2 | |
| 3 | struct Vec5 { |
| 4 | x f64 |
| 5 | y f64 |
| 6 | z f64 |
| 7 | a f64 |
| 8 | b f64 |
| 9 | } |
| 10 | |
| 11 | fn vec5_from(value f64) Vec5 { |
| 12 | return Vec5{value, value, value, value, value} |
| 13 | } |
| 14 | |
| 15 | fn (v Vec5) abs_oldstyle() Vec5 { |
| 16 | return Vec5{math.abs(v.x), math.abs(v.y), math.abs(v.z), math.abs(v.a), math.abs(v.b)} |
| 17 | } |
| 18 | |
| 19 | fn (v Vec5) generic_new(f fn (f64) f64) Vec5 { |
| 20 | return Vec5{f(v.x), f(v.y), f(v.z), f(v.a), f(v.b)} |
| 21 | } |
| 22 | |
| 23 | fn test_generic_function_argument_inference() { |
| 24 | v := vec5_from(-1.0) |
| 25 | assert v.generic_new(math.abs) == v.abs_oldstyle() |
| 26 | } |
| 27 | |