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-15706] Swift >= 5.5.1 crashes on type inference #57985

Closed
swift-ci opened this issue Jan 8, 2022 · 4 comments
Closed

[SR-15706] Swift >= 5.5.1 crashes on type inference #57985

swift-ci opened this issue Jan 8, 2022 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jan 8, 2022

Previous ID SR-15706
Radar None
Original Reporter Hoogervorst (JIRA User)
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

Xcode 13.2+, MacOS Big Sur 11.6.2 (20G314)

It works fine with Xcode 12.5.x (same OS).

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

md5: e3860928bd2c149983e5f21966ce2448

Issue Description:

Not sure why it crashes, but in the attached source code file Swift 5.5.1 and Swift 5.5.2 crash on the following line:

public init<LV>(_ lhs: WritableKeyPath<L, LV>) where LV: Equatable, L == R

This constructor is inferred from the the `value` the keypath refers to.

I attached an example source code file (which also includes the stack trace).

Thanks.

@CodaFi
Copy link
Member

CodaFi commented Jan 19, 2022

Reproduces in Xcode 13, but not on mainline. Seems like the requirement machine enablement tackled this.

Please verify that this crash is resolved in a nightly toolchain.

@swift-ci
Copy link
Collaborator Author

Comment by Alfons (JIRA)

@CodaFi Confirmed to work with the January 9, 2022 development snapshot. Thank you.

Edit: For good measure: also with the Swift 5.6 Snapshot of Jan 11, 2022

@swift-ci
Copy link
Collaborator Author

Comment by Alfons (JIRA)

I was able to work around the issue by making swift infer a `convenience` constructor.

public final class PropertyMapping<L: AnyObject, R: AnyObject> {
    
    public init<V>(_ lhs: WritableKeyPath<L, V>, _ rhs: WritableKeyPath<R, V>) where V: Equatable {
        self.neglect = true
    }


    #if (swift(>=5.4) && swift(<5.5)) || swift(>=5.6)
    // Not in Swift 5.5
    public init<LV>(_ lhs: WritableKeyPath<L, LV>) where LV: Equatable, L == R {
        self.neglect = true
    }
    #endif


    
    let neglect: Bool
}

#if (swift(>=5.5) && swift(<5.6))
public extension PropertyMapping where L == R {
    
    // Swift 5.5 only
    convenience init<LV>(_ lhs: WritableKeyPath<L, LV>) where LV: Equatable, L == R {
        self.init(lhs, lhs)
    }
    
}
#endif // Swift 5.5

(which is arguably also a sane approach)

@swift-ci
Copy link
Collaborator Author

Comment by Alfons (JIRA)

Closed

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

No branches or pull requests

2 participants