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-4698] Compiler aborts due to segmentation fault with operator overloading #47275

Closed
swift-ci opened this issue Apr 25, 2017 · 5 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4698
Radar None
Original Reporter keshav vishwkarma (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 8.3, 8.3.1 & 8.3.2

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

md5: 04da073b449197f8764045007efc5985

Issue Description:

The following code causes a compiler issue in 3.1, while it worked on 3.0: -
Here is the code:

import UIKit

public protocol Addable: class {
    static func +(lhs: Self, rhs: NSLayoutConstraint) -> NSLayoutConstraint
    static func +(lhs: Self, rhs: [NSLayoutConstraint]) -> [NSLayoutConstraint]
}

extension UIView : Addable {}
extension Addable where Self: UIView
{
    /// To add single constraint on the lhs view
    public static func +(lhs: Self, rhs: NSLayoutConstraint) -> NSLayoutConstraint {
            lhs.addConstraint(rhs)
            return rhs
    }
    
    /// To add multiple constraints on the lhs view
    public static func +(lhs: Self, rhs: [NSLayoutConstraint]) -> [NSLayoutConstraint] {
           return rhs.map { lhs + $0 }
    }
}

Note: - Now If we remove Second method of protocol & we also remove its implementation part from protocol extension then the remaining code is compilable.

As far as I know there is something wrong with — rhs.map { lhs + $0 } in the second method of Addable. means using the first method inside the second method.

If we use the same code with custom operators in the same way then the issue will remain same. Here is the link to my project KVConstraintKit in which I have made few custom operators and all of them having the same issues but works fine in swift 3.0.

@belkadan
Copy link
Contributor

Seems to be working fine in master. @slavapestov, did we fix anything here recently?

@slavapestov
Copy link
Member

We should add a regression test (hopefully with NSLayoutConstraint replaced by something similar to avoid a UIKit dependency)

@belkadan
Copy link
Contributor

Yeah, I suspect UIView and NSLayoutConstraint have nothing to do with the original bug.

@swift-ci
Copy link
Collaborator Author

Comment by Keshav Vishwkarma (JIRA)

@slavapestov I have written a code without UIKit dependency. Please have a look in attached file & @belkadan Yes, you are right.

@slavapestov
Copy link
Member

I don't remember the exact bug, but this was fixed a while ago. I verified that the test case passes on Swift 4.2 as well as the master branch.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

4 participants