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
When a protocol defined in one file references a type defined in a separate module, but a type defined in another file that doesn’t import the separate module tries to conform to the protocol, the Swift compiler gives a confusing fixit that doesn’t fix the error, but causes a new error.
// Module2/WidgetCounter.swift// Without this import, WidgetCounter cannot conform to WidgetCounting:// import Module1structWidgetCounter: WidgetCounting {
funccountWidgets() -> Result<Int, Error> { // Swift.Result, not Module1.Resultreturn .success(42)
}
}
The compiler gives the following diagnostic and confusing fixit:
error: type 'WidgetCounter' does not conform to protocol 'WidgetCounting'
note: candidate has non-matching type '() -> Result<Int, Error>'
note: protocol requires function 'countWidgets()' with type '() -> Result<Int, Error>'; do you want to add a stub?
When you apply the fixit, WidgetCounter now has two countWidgets() methods with type () -> Result<Int, Error>, so you get a new diagnostic, error: invalid redeclaration of 'countWidgets()'.
WidgetCounting is using Module1.Result, but WidgetCounter doesn’t import Module1, so it’s using Swift.Result. The initial diagnostic should make this distinction clear, and the fixit should either add import Module1 or explicitly specify Module1.Result instead of adding the unqualified Result.
The text was updated successfully, but these errors were encountered:
The SR-11024 fix isn't able to help in this case because it only disambiguates types which appear together in a diagnostic message. It looks like this bug still exists on master, it'll probably require a tailored fix to handle the stub insertion fixit properly.
Environment
Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Target: x86_64-apple-darwin18.6.0
Additional Detail from JIRA
md5: 1643cef766ac65aad555ced43c795fe9
is duplicated by:
relates to:
Issue Description:
Potentially fixed when https://bugs.swift.org/browse/SR-11024 was fixed, but I wanted to make sure.
When a protocol defined in one file references a type defined in a separate module, but a type defined in another file that doesn’t import the separate module tries to conform to the protocol, the Swift compiler gives a confusing fixit that doesn’t fix the error, but causes a new error.
The compiler gives the following diagnostic and confusing fixit:
When you apply the fixit,
WidgetCounter
now has twocountWidgets()
methods with type() -> Result<Int, Error>
, so you get a new diagnostic,error: invalid redeclaration of 'countWidgets()'
.WidgetCounting
is usingModule1.Result
, butWidgetCounter
doesn’t importModule1
, so it’s usingSwift.Result
. The initial diagnostic should make this distinction clear, and the fixit should either addimport Module1
or explicitly specifyModule1.Result
instead of adding the unqualifiedResult
.The text was updated successfully, but these errors were encountered: