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-7341] Type checker regression for multiple properties with different return types as of March 28 master snapshot #49889

Closed
swift-ci opened this issue Apr 3, 2018 · 11 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.2 type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 3, 2018

Previous ID SR-7341
Radar rdar://problem/39877485
Original Reporter benasher44 (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

macOS 10.13.4
Xcode 9.3 w/ Swift 4.1 (App Store version)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.2Regression, TypeChecker
Assignee @hamishknight
Priority Medium

md5: 0f27ae3ae554c0de612033abe1dbe496

Issue Description:

Our project uses the open source project ReactiveObjCBridge, which helps bridge the ReactiveObjC and ReactiveSwift worlds. While trying to reproduce and check for fixes for SR-7206, I ran into a new type checker issue that has been present since the March 28 master snapshot and still isn't fixed as of the April 2 master snapshot (not necessarily expecting a fix, but sometimes issues come and go on master). Here's the section of code in question in ReactiveObjCBridge:

extension Action {
    fileprivate var isEnabled: RACSignal<NSNumber> {
        return self.isEnabled.producer.map { $0 as NSNumber }.bridged
    }
}

With that isEnabled decl, there becomes 2 isEnabled properties with different return types on the same type. In Swift 4.1 this compiles fine, but in these recent snapshots you get an error about `RACSignal<NSNumber>` having no member 'producer'. This is easily corrected (at least temporarily to work through this issue and move on with compiling) by updating this line to:

return (self.isEnabled as Property<Bool>).producer.map { $0 as NSNumber }.bridged

I believe this forces it to pick the correct self.isEnabled, but then you get this type error about the map closure: Cannot convert value of type '(NSNumber) -> NSNumber' to expected argument type '(_) -> _'. I haven't been able to get passed this one, but in general it seems like there's a type checker issue that's worth reporting here.

Unfortunately, the open source project doesn't meet a few of the requirements for adding it to the source compat suite. I'm fairly certain this project no longer builds in Swift 3 compatibility mode, and it also requires Carthage or CocoaPods to build correctly. Given that, I've attached a zip file with a sample project with this dependency. You could be able to just open the sample project workspace and build using any of the snapshots mentioned to reproduce this issue. Thanks in advance!

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

I tried coming up with a smaller test case:
file1.swift

final class Wrapper<Wrapped> {
    let value: Wrapped
    init(value: Wrapped) { self.value = value }
}

final class Action {
    let isEnabled: Wrapper<Int>
    init() { self.isEnabled = Wrapper(value: 1) }
}

file2.swift

final class OtherWrapper<Wrapped> {
    let value: Wrapped
    init(value: Wrapped) { self.value = value }
}

extension Action {
    fileprivate var isEnabled: OtherWrapper<Bool> { return OtherWrapper(value: self.isEnabled.value != 0) }
}

However, that code compiles fine in Swift 4.1, the March 28 master snapshot, and April 20 master snapshot. But, the attached zipped project still doesn't build in the March 28 master snapshot, nor the latest April 20 master snapshot.

This is the main issue preventing us from verifying SR-7337 as well as testing the new batch mode.

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

Okay I had a look at PRs that landed between the March 26 master snapshot (when this last worked) and the March 28 master snapshot (when this first regressed), and this PR seems like a likely culprit given the PR description + related bugs it closed: #15412

@hamishknight does that seem plausible? If so, would you mind having a look at the attached sample project?

@hamishknight
Copy link
Collaborator

Here's a reduced test case, it requires two modules:

Module A, a.swift:

public class Action<T> {
  public var i = 0
}

Module B, b.swift:

import A

extension Action {
  var i: String {
    let x: Int = i // in 4.1 no error, in the 2018-04-18 snapshot error: Cannot convert value of type 'String' to specified type 'Int'
    return String(x)
  }
}

The above compiles in 4.1, but doesn't in the 2018-04-18 snapshot.

I'm not sure what the exact cause of the problem is (and unfortunately I don't quite have the time to look into it in detail at the moment), though I agree that it's likely a result of #15412 – previously we would have given i two different overload types and therefore would have treated them as two distinct overloads, whereas now they have the same overload type (but we still allow the overload as it's in a different module).

Though i would have only had different overload types while Action had a generic placeholder, if we remove the <T> from the above example, then it will also fail to compile in 4.1 (what my change did was bring the generic behaviour in line with the non-generic).

@hamishknight
Copy link
Collaborator

cc @belkadan

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

No problem![]( Thank you so much for providing the small repro case and all of the extra context)

@belkadan
Copy link
Contributor

belkadan commented May 1, 2018

Thanks to both of you. Hm, I wonder if the type checker wasn't prepared to deal with property overloads.

@swift-ci create

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jun 4, 2018

Comment by Ben A (JIRA)

This is still an issue in the Xcode 10 beta. I know you all must have been super busy leading up to today's announcements; just wanted to flag this again as it's the major blocker for us doing any beta testing, batch mode testing, etc. Thanks!

@nkcsgexi
Copy link
Member

nkcsgexi commented Jun 5, 2018

We saw this in WWDC 18 lab that this issue stops users from using Xcode 10 with Pods.

@belkadan
Copy link
Contributor

belkadan commented Jun 6, 2018

cc @DougGregor

@hamishknight
Copy link
Collaborator

#18488

@hamishknight
Copy link
Collaborator

The above linked PR resolves the issue in Swift 5 under Swift 4 compatibility mode. I’ve filed https://bugs.swift.org/browse/SR-8619 to track a broader Swift 5 mode change where we no longer shadow another module’s property overload regardless of whether the two properties are defined in extensions of generic types.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 regression swift 4.2 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

5 participants