Skip to content
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-7346] ReactiveCocoa source breakage: error: value of optional type 'IMP??' (aka 'Optional<Optional<OpaquePointer>>') not unwrapped #49894

Open
clackary opened this issue Apr 3, 2018 · 8 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@clackary
Copy link
Contributor

clackary commented Apr 3, 2018

Previous ID SR-7346
Radar rdar://problem/39181014
Original Reporter @clackary
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: b800acddc7c117f5ac027e393586049a

Issue Description:

To reproduce:

  1. Install latest GM/Beta Xcode
  2. $ git clone git@github.com:apple/swift-source-compat-suite.git
  3. $ cd swift-source-compat-suite

To build Swift from scratch before testing:
4. $ ./reproduce.py swift-4.1-branch --project-path ReactiveCocoa

Or if you've already built Swift:
4. $ ./reproduce.py swift-4.1-branch --project-path ReactiveCocoa --swiftc path/to/swiftc

Build #264 of swift-4.1-source-compat-suite

FAIL_ReactiveCocoa_3.2_BuildXcodeWorkspaceScheme_ReactiveCocoa-iOS_generic-platform-iOS.log
FAIL_ReactiveCocoa_3.2_BuildXcodeWorkspaceScheme_ReactiveCocoa-macOS_generic-platform-macOS.log
FAIL_ReactiveCocoa_3.2_BuildXcodeWorkspaceScheme_ReactiveCocoa-tvOS_generic-platform-tvOS.log
FAIL_ReactiveCocoa_3.2_BuildXcodeWorkspaceScheme_ReactiveCocoa-watchOS_generic-platform-watchOS.log

/Users/buildnode/jenkins/workspace-private/swift-4.1-source-compat-suite/project_cache/ReactiveCocoa/ReactiveCocoa/NSObject+Intercepting.swift:229:47: error: value of optional type 'IMP??' (aka 'Optional<Optional<OpaquePointer>>') not unwrapped; did you mean to use '!' or '?'?
                                _ = class_replaceMethod(realClass, alias, impl, typeEncoding)
                                                                          ^
@clackary
Copy link
Contributor Author

clackary commented Apr 3, 2018

This looks like another case of disallowed IUOs, like in SR-7273.

@clackary
Copy link
Contributor Author

clackary commented Apr 3, 2018

Was able to reproduce this locally, but it failed with the 4.0 configurations in addition to 3.2.

FAIL: ReactiveCocoa, 4.0, 72dd20, ReactiveCocoa-watchOS, generic/platform=watchOS
FAIL: ReactiveCocoa, 4.0, 72dd20, ReactiveCocoa-tvOS, generic/platform=tvOS
FAIL: ReactiveCocoa, 4.0, 72dd20, ReactiveCocoa-iOS, generic/platform=iOS
FAIL: ReactiveCocoa, 4.0, 72dd20, ReactiveCocoa-macOS, generic/platform=macOS
FAIL: ReactiveCocoa, 3.2, 72dd20, ReactiveCocoa-watchOS, generic/platform=watchOS
FAIL: ReactiveCocoa, 3.2, 72dd20, ReactiveCocoa-tvOS, generic/platform=tvOS
FAIL: ReactiveCocoa, 3.2, 72dd20, ReactiveCocoa-iOS, generic/platform=iOS
FAIL: ReactiveCocoa, 3.2, 72dd20, ReactiveCocoa-macOS, generic/platform=macOS

@clackary
Copy link
Contributor Author

clackary commented Apr 4, 2018

I've reached out to the ReactiveCocoa maintainer for an updated hash.

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 4, 2018

Comment by Anders Ha (JIRA)

@clackary It seems to be a legit regression. There is no IUO involved here at least from a language user POV (according to Xcode Quick Tips).

`method` is `Method?`. `method_getImplementation` is `(Method) -> IMP`. `_rac_objc_msgForward` is `IMP`. So the resulting line should have produced `IMP`.

The interesting bit is that it compiles fine if I explicitly declare the result type to be `IMP`. So it seems more like a type inference issue to me.

@clackary
Copy link
Contributor Author

clackary commented Apr 4, 2018

@swift-ci create

@rudkx
Copy link
Member

rudkx commented Apr 9, 2018

When compiling with -swift-version 3, IUOs actually do come into play here because the API notes for method_getImplementation (and class_getInstanceMethod) say that they take IUOs and return IUOs.

import Foundation

func test(m: Method?, i: IMP) {
  let r = m.map(method_getImplementation) ?? i
  let _: IMP = r
}

This is a simplified example that demonstrates the problem.

I'll take a closer look at this soon, but what it looks like is happening is that for some reason the type checker is now selecting the ?? that returns T? rather than the one that returns T.

@rudkx
Copy link
Member

rudkx commented Apr 9, 2018

I've attached a reduced test case that more closely represents the original code.

@rudkx
Copy link
Member

rudkx commented Apr 9, 2018

For now I would suggest working around the issue when compiling with compilers built from swift-4.1-branch by explicitly typing 'impl' as 'IMP'.

Compilers built with swift-4.2-branch and master appear to compile this without error.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

3 participants