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-988] Undiagnosed type error in subclass function with Self return type #43600

Closed
ddunbar opened this issue Mar 19, 2016 · 0 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 run-time crash Bug → crash: Swift code crashed during execution type checker Area → compiler: Semantic analysis

Comments

@ddunbar
Copy link
Member

ddunbar commented Mar 19, 2016

Previous ID SR-988
Radar None
Original Reporter @ddunbar
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, RunTimeCrash, TypeChecker
Assignee None
Priority Medium

md5: f4e27707243b5d6f3bf146b510e643de

duplicates:

  • SR-695 Loophole in Self-requirement leads to crash

Issue Description:

The following code should fail to compile, because B is violating the Self return contract of P, which is conformed to by A. This crashes at runtime because we manage to get an object of type C (via the generic shim `f0`) which is actual only a B.

$ cat z.swift 
protocol P {
    func foo() -> Self
}

class A: P {
    required init() {}
    func foo() -> Self { return self.dynamicType.init() }
}
class B: A {
    override func foo() -> B { return B() }
}
class C: B {
    func baz() { print("baz!") }
}

func f0<T: P>(t: T) -> T { return t.foo() }

let c: C = f0(C())
c.baz()

$ swiftc z.swift  && ./z
Segmentation fault: 11
@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants