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-6390] Let protocols inherit from class types #48940

Closed
sjavora opened this issue Nov 15, 2017 · 6 comments
Closed

[SR-6390] Let protocols inherit from class types #48940

sjavora opened this issue Nov 15, 2017 · 6 comments
Assignees
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 run-time crash Bug → crash: Swift code crashed during execution

Comments

@sjavora
Copy link
Contributor

sjavora commented Nov 15, 2017

Previous ID SR-6390
Radar rdar://problem/34812895
Original Reporter @sjavora
Type Bug
Status Closed
Resolution Duplicate
Environment

Xcode 9.1 (9B55)

macOS 10.13.1 (17B48)

iMac (Retina 5K, 27-inch, Late 2015)

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

md5: 3d9ddb6c1aaf70e254c01f4bcb81d316

duplicates:

  • SR-6000 Let protocols inherit from class types

Issue Description:

Probably best explained through an example:

class BaseClass {}

protocol ClassConstraining where Self: BaseClass { // remove `where Self: BaseClass` to stop crashing
    var value: Int64? { get }
}

class DerivedClass: BaseClass, ClassConstraining {
    var value: Int64?
    
    init(value: Int64?) { 
        self.value = value
        super.init()
    }
}

let derived = DerivedClass(value: 3)

let base: BaseClass = derived

(base as? ClassConstraining)?.value

In a playground, this results in a crash. In a project with optimizations enabled, a seemingly random value is returned.

Removing where Self: BaseClass correctly returns the value.

I am not even sure if the constrained protocol is a supported feature, only learned about it a few weeks ago on Stack Overflow.

@belkadan
Copy link
Contributor

@slavapestov, you've got one of these, right?

@tkrajacic
Copy link

Still happens in Xcode 9.3 and Swift 4.1

@belkadan
Copy link
Contributor

@swift-ci create

(just to be sure)

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Jul 23, 2019

@sjavora, Could you verify if the problem is fixed and if so move the JIRA to "Closed"?

Thanks!
Anna

@sjavora
Copy link
Contributor Author

sjavora commented Aug 7, 2019

I have verified that this has been fixed

@sjavora
Copy link
Contributor Author

sjavora commented Aug 7, 2019

@AnnaZaks done, sorry for the delay!

@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 run-time crash Bug → crash: Swift code crashed during execution
Projects
None yet
Development

No branches or pull requests

4 participants