Guest User

Untitled

a guest
May 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. Vec2: class {
  2. x, y: Float
  3. init: func (=x, =y)
  4. repr: func -> String { "Vec2(%.2f, %.2f)" format(x, y) }
  5. }
  6.  
  7. operator * (left: Float, right: Vec2) -> Vec2 {
  8. return Vec2 new(left * right x, left * right y)
  9. }
  10.  
  11. main: func {
  12. v1 := Vec2 new(1.0, 1.0)
  13.  
  14. v2 := 2.0 * v1
  15. // Fails: test.c:91: error: incompatible types when initializing type
  16. // 'lang_Numbers__Float' using type 'struct test__Vec2 *'
  17. // Note: v2 is is being inferred as a Float and assigned a Vec2.
  18.  
  19. v3: Vec2 = 2.0 * v1
  20. v3 repr() println()
  21. // Works: Vec2(2.0, 2.0)
  22.  
  23. v4 := (2.0 * v1) as Vec2
  24. v4 repr() println()
  25. // Works: Vec2(2.0, 2.0)
  26. }
Add Comment
Please, Sign In to add comment