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
Xcode 9.2 (9C40b)
Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)
Target: x86_64-apple-macosx10.9
Also occurs with the latest 4.1 snapshot:
Apple Swift version 4.1-dev (LLVM c4ec2ab808, Clang d8b11579e8, Swift c8e3724)
Target: x86_64-apple-darwin16.7.0
Additional Detail from JIRA
Votes
0
Component/s
Compiler
Labels
Bug
Assignee
None
Priority
Medium
md5: 09409a9d09b0830edfcee49a1007453c
duplicates:
SR-6993 Swift imports @optional ObjC methods from superclass protocol as if implemented
Issue Description:
When an Obj-C class conforms to a protocol with optional methods, and you use that Obj-C class from Swift, the compiler incorrectly assumes the class implements all of the optional methods. You can see this in the autocomplete menu where it lists a non-optional version of the method right next to the IUO-version of the method. And you can confirm this by trying to use optional-chaining on the method and the seeing a compiler error telling you the method isn't optional.
// SomeSwiftFile.swiftletfoo = ObjCClass()
print(foo.foobar?() ?? "unimplemented")
// error: Cannot use optional chaining on non-optional value of type '() -> String'
And here's what autocomplete is showing:
![](Screen Shot 2018-02-23 at 2.12.06 PM.png)
The text was updated successfully, but these errors were encountered:
Thankfully invoking the method from Swift can be accomplished by casting the object to the protocol first, where the method is still optional (well, IUO). But it's awkward and really easy to miss and attempt to invoke a method that doesn't exist.
Attachment: Download
Environment
Xcode 9.2 (9C40b)
Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)
Target: x86_64-apple-macosx10.9
Also occurs with the latest 4.1 snapshot:
Apple Swift version 4.1-dev (LLVM c4ec2ab808, Clang d8b11579e8, Swift c8e3724)
Target: x86_64-apple-darwin16.7.0
Additional Detail from JIRA
md5: 09409a9d09b0830edfcee49a1007453c
duplicates:
Issue Description:
When an Obj-C class conforms to a protocol with optional methods, and you use that Obj-C class from Swift, the compiler incorrectly assumes the class implements all of the optional methods. You can see this in the autocomplete menu where it lists a non-optional version of the method right next to the IUO-version of the method. And you can confirm this by trying to use optional-chaining on the method and the seeing a compiler error telling you the method isn't optional.
And here's what autocomplete is showing:
![](Screen Shot 2018-02-23 at 2.12.06 PM.png)
The text was updated successfully, but these errors were encountered: