New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-7046] Autocomplete suggests methods that can't be called on certain instances #49594
Comments
Comment by Will Lisac (JIRA) Using a protocol in the where clause is a possible workaround for this code completion issue. class A<T> { }
extension A where T == String {
// This method will always be visible in code completion
func fooString() { }
}
extension A where T: StringProtocol {
// This method will only be visible when T conforms to StringProtocol
func fooStringProtocol() { }
}
let example = A<Bool>()
example.foo |
The protocol-workaround only works when all code is in the same swift file, if you put the class and extensions and the calling code in separate files, it will list all extensions again. Another very similar attempted workaround detailed example here will show the same behavior, ie working only if all code is in the same file. |
I guess the following might be another manifestation of this issue:
I mean the supposedly helpful "did you mean `count`?" and the fact that `.count` is in the list of code completions, even though `Range<Float>` does not have a `.count` member. |
This has been fixed in #23065 |
This has been fixed in #23332 |
Thanks, Rintaro! |
Is this supposed to be fixed in the default toolchain of Xcode 10.2.1? I see Rintaro saying above that it has been fixed but the issue as described here (in SR-7046) and in the linked SR-9396 remains as of default toolchain of Xcode 10.2.1. That is, for example the following is still what happens in Xcode 10.2.1:
even though Range<Float> has no property called count. |
Not for Xcode 10.2.1 (Swift 5.0.1). Please wait for Swift 5.1. |
Attachment: Download
Environment
Xcode Version 9.2 (9C40b)
Additional Detail from JIRA
md5: 2666fe154a7afbbb66b70fdd218be9a2
relates to:
Issue Description:
On the screenshot, `foo` can't be called on b, and the compiler will rightly show an error if I hit enter on the Autocomplete suggestion below.
![](Screen Shot 2018-02-21 at 1.41.38 AM.png)
I am not sure if Autocomplete is currently meant to be this smart, but if by any chance it is, here you go.
Another example:
The text was updated successfully, but these errors were encountered: