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-11611] Generic instantiation broken for specific case #54019

Open
swift-ci opened this issue Oct 14, 2019 · 8 comments
Open

[SR-11611] Generic instantiation broken for specific case #54019

swift-ci opened this issue Oct 14, 2019 · 8 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 5.1

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11611
Radar rdar://problem/56262165
Original Reporter mlwoollard (JIRA User)
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 5.1Regression
Assignee @slavapestov
Priority Medium

md5: 0246f94be1e0ded3b759c985ed36a797

Issue Description:

I have some code that is basically:

// Module 1
public protocol P {
    associatedtype A
    associatedtype B
    init()
    func run(a: A) -> B
}

public protocol C {}

open class C1<A, B: C>: P {
    required init() {}
    open func run(a: A) { return // some instance of B }
}

// Module 2
public protocol T {}

// Module 3
class CC: C {}

class C2: C1<T, CC> {
    override func run(a: A) -> B {...}
}

// Then have extension to Set
extension Set where Element: C2 {
   func getC2() -> Element {
       return Element.init()
   }
}

With Xcode 10.3 / Swift 5.0.1 this works as expected and getC2() return instance of C2. However with Xcode 11.1 / Swift 5.1 getC2() is returning instance of C1<T, CC> and so when `run(a: A)` is called the base class method is called and not the C2 overridden method.

For the real case, `print("(instanceOfInstantiatedClass)")` immediately after the code instantiates an instance as indicated above, same code compiled in the two environments:

Swift 5.0.1 outputs the subclass as expected

`TicketlessCore.ProductCellCoordinator`

Swift 5.1 outputs the base class with generic parameters provided by subclass (and breaks things as the subclass overridden method does not get called).

`UTMMVC.CellCoordinator<UTProducts.TicketProduct, TicketlessCore.ProductCell>`

This is part of large complex project and I've not yet been able to reproduce in simpler form suitable for adding here (but will continue to try to do so). If there's anything else that can help let me know and any suggestions of a work around?

@belkadan
Copy link
Contributor

I think we're going to have to see the project to make progress. If you can't share it here, how about filing a Feedback for just the Apple folks to look into it? (https://feedbackassistant.apple.com)

@slavapestov, does this sound familiar?

@swift-ci
Copy link
Collaborator Author

Comment by Mark Woollard (JIRA)

I'll try and get something together that reproduces this and share as suggested. It can probably do that without having to share everything but using the actual code involved above.

@swift-ci
Copy link
Collaborator Author

Comment by Mark Woollard (JIRA)

I've distilled this down into a much smaller project that reproduces the issue. Zip attached contains project, open the workspace and build and run. Set a breakpoint at `BugCell.swift:19`, compiled with 5.0.1 this breakpoint is hit, compiled with 5.1 it is not.

See `UTMVVMC/Set+CellCoordinator.swift:16`. This is where the problem instantiation occurs, with 5.0.1 it instantiates `BugCoordinator`, with 5.1 `CellCoordinator<(), BugCell>` !

instantiation-bug.zip

@belkadan
Copy link
Contributor

Thanks for the reduction!

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by Mark Woollard (JIRA)

Is there any idea on timescale to resolution of this, currently its blocking us moving to 5.1 / iOS 13. Some indication would help decide whether to look at a re-architecture or wait. Thanks.

@swift-ci
Copy link
Collaborator Author

Comment by Mark Woollard (JIRA)

I've discovered something else about this issue. Our app build with Xcode 11.3 / Swift 5.1.3 for release / bitcode and uploaded to iTunes, when processed by Apple and then installed, does not exhibit the bug. Same code compiled locally onto device, or in simulator does. Don't know if that helps !

@slavapestov
Copy link
Member

I noticed that the problem does not reproduce on the 5.2 compiler, but I wasn't able to make any progress on figuring out what was going wrong in 5.1. Can you try a 5.2 development snapshot and confirm that the issue has been addressed?

@swift-ci
Copy link
Collaborator Author

Comment by Mark Woollard (JIRA)

Confirm that example provided here compiles and works correctly with the Jan 16th snapshot. I haven't been able to verify on our main codebase since this version causes compiler error with a third partly pod (Stripe SDK) and not had time to resolve issue.

@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 regression swift 5.1
Projects
None yet
Development

No branches or pull requests

4 participants