Last active
December 31, 2015 21:36
-
-
Save chris-hatton/2136362ed37d0d4219b0 to your computer and use it in GitHub Desktop.
Significance of top-level definition of overloaded functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ProtocolA {} | |
protocol ProtocolB {} | |
func overloadingTest <T where T: ProtocolA>( obj: T ) -> String | |
{ | |
return "It's an implementation of Protocol A" | |
} | |
func overloadingTest <T where T: ProtocolB>( obj: T ) -> String // This compiles fine, and the appropriate 'topLevelTest' function is bound | |
{ | |
return "It's an implementation of Protocol B" | |
} | |
func aFunction() | |
{ | |
func nestedOverloadingTest <T where T: ProtocolA>( obj: T ) -> String | |
{ | |
return "It's an implementation of Protocol A" | |
} | |
func nestedOverloadingTest <T where T: ProtocolB>( obj: T ) -> String // Fails to compile with 'Definition conflicts with previous value' | |
{ | |
return "It's an implementation of Protocol B" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My wild guess is that nested functions become scoped values assigned to a reference to the function, rather than using regular function/method resolution.