swift - How do you test functions and closures for equality? -
the book says "functions , closures reference types". so, how find out if references equal? == , === don't work.
func a() { } let å = let b = å === å // not find overload === accepts supplied arguments
here how catterwauls dealing this:
chris lattner wrote on developer forums:
this feature intentionally not want support. there variety of things cause pointer equality of functions (in swift type system sense, includes several kinds of closures) fail or change depending on optimization. if "===" defined on functions, compiler not allowed merge identical method bodies, share thunks, , perform capture optimizations in closures. further, equality of sort extremely surprising in generics contexts, can reabstraction thunks adjust actual signature of function 1 function type expects.
https://devforums.apple.com/message/1035180#1035180
this means should not try compare closures equality because optimizations may affect outcome.
Comments
Post a Comment