Environment
Swift 4.1 or 4.2, observed with Xcode 9.3 and Xcode 9.4
Additional Detail from JIRA
| | |
|------------------|-----------------|
|Votes | 0 |
|Component/s | CodeCompletion |
|Labels | Bug |
|Assignee | None |
|Priority | Medium |
md5: 3e98fa5aa6452918412c6b6bee1804f1
Issue Description:
If you have two modules declare the same for a type, say `Result`, and then have a protocol which includes the Result type in one of its arguments, Swift fails to resolve the name conflict when completing the protocol method definition, either with Fix-It or autocomplete. On top of this, the verbalised messages for the build compilation errors are confusing and do not accurately describe the issue. Demo video.
In `ExampleOtherModule`:
public enum Result {
// result type defined in `ExampleOtherModule`
}
public protocol ExampleProtocol { // protocol that uses the local Result type in a method
func didFinish(with result: Result)
}
In main module:
enum Result { // result type defined in module
}
class AppDelegate : ExampleProtocol {
func didFinish(with result: Result) { // this is what Swift/Xcode autocompletes but it is incorrect and will not build
}
}
The produced error by following Xcode's lead is: 'Type AppDelegate does not conform to protocol `ExampleProtocol`. This is because `Result` is resolved to be the module-local type, not the type that the protocol obviously refers to.
The correct formulation should be `didFinish(with result: ExampleOtherModule.Result)`. I have made a quick demo video to better show the problem here. Example project is also attached, if it helps.
Debugging this is inscrutable for users not familiar with the modules in a project. I have hit this in the past and this bug report was triggered by an issue posted to GitHub of someone trying to use one of my open-source projects and getting lost when they hit this same problem.
Attachment: Download
Environment
Swift 4.1 or 4.2, observed with Xcode 9.3 and Xcode 9.4Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | CodeCompletion | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 3e98fa5aa6452918412c6b6bee1804f1Issue Description:
If you have two modules declare the same for a type, say `Result`, and then have a protocol which includes the Result type in one of its arguments, Swift fails to resolve the name conflict when completing the protocol method definition, either with Fix-It or autocomplete. On top of this, the verbalised messages for the build compilation errors are confusing and do not accurately describe the issue. Demo video.
In `ExampleOtherModule`:
In main module:
The produced error by following Xcode's lead is: 'Type AppDelegate does not conform to protocol `ExampleProtocol`. This is because `Result` is resolved to be the module-local type, not the type that the protocol obviously refers to.
The correct formulation should be `didFinish(with result: ExampleOtherModule.Result)`. I have made a quick demo video to better show the problem here. Example project is also attached, if it helps.
Debugging this is inscrutable for users not familiar with the modules in a project. I have hit this in the past and this bug report was triggered by an issue posted to GitHub of someone trying to use one of my open-source projects and getting lost when they hit this same problem.