Skip to content

Instantly share code, notes, and snippets.

@ftsf
Created May 29, 2017 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ftsf/37c93b0fbd768ea9122b5513e6d1b348 to your computer and use it in GitHub Desktop.
Save ftsf/37c93b0fbd768ea9122b5513e6d1b348 to your computer and use it in GitHub Desktop.
strange proc lookup
type
Vec2[T] = tuple
x,y: T
Vec2f = Vec2[float32]
proc vec2f(x,y: float): Vec2f =
result.x = x
result.y = y
proc `-`[T](a,b: Vec2[T]): Vec2[T] =
result.x = a.x - b.x
result.y = a.y - b.y
proc foo[T](a: Vec2[T]): Vec2[T] =
result = a
block:
# this being called foo is a problem when calling .foo()
var foo = true
let a = vec2f(1.0,0.0)
let b = vec2f(3.0,1.0)
let c = (a - b).foo() # breaks
# let c = foo(a - b) # works
## results in
# test.nim(23, 14) Error: type mismatch: got (Vec2, Vec2)
# but expected one of:
# proc `-`[T](a, b: Vec2[T]): Vec2[T]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment