You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The compiler complains that there's an extra argument existingAccounts within the call. There is hence no way to address the function outside of the controller class without renaming it. The compiler should consider it as an overload candidate as well. Since self. is not explicitely mentioned, the compiler should use the file-level function.
The text was updated successfully, but these errors were encountered:
Normally you use the name of the module to disambiguate: MyApp._validateAccountName. Playgrounds don't have a standard module name, though, so that's still a problem.
IMHO there should be a chain of precedence for shadowing where globally (file-level) declared symbols take precedence over references to instance members without explicit self as one would expect. In this example:
privatefunc_validateAccountName(name: String) -> Bool {
// Logic goes here...
}
classMyController {
privatefunc_validateAccountName(name: String) -> Bool {
_validateAccountName("123") // Calls file-level function, even if it has the same signature as the instance method on MyControllerself._validateAccountName(name) // Calls instance method
}
}
Nevertheless, in my original example, the file-level function has different signature (contains two arguments), unlike the instance method on MyController which only contains one argument, so it shouldn't be ambiguous at all.
There is a chain of precedence, but it's always inner scope to outer scope, and only checking base names. That's a deliberate design (whether or not it's a good one), so any changes would need to go through the Swift Evolution Process.
Attachment: Download
Environment
OS X 10.11.5, Xcode 8b1
Additional Detail from JIRA
md5: 8b397a0255bb33a4d7a23649ea2b6c11
is duplicated by:
relates to:
type
from the functiontype(of:)
Issue Description:
I'm attaching a playground file that demonstrates the issue:
Have a function at the file-level:
which includes a name-checking logic which you want to be shared among several components in the file.
Then create class that has the following method:
The compiler complains that there's an extra argument existingAccounts within the call. There is hence no way to address the function outside of the controller class without renaming it. The compiler should consider it as an overload candidate as well. Since self. is not explicitely mentioned, the compiler should use the file-level function.
The text was updated successfully, but these errors were encountered: