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-4736] Passing self to super.init before initialization is incorrectly allowed #47313

Closed
rnapier opened this issue Apr 29, 2017 · 1 comment
Labels
accepts invalid Bug: Accepts invalid bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself definite initialization

Comments

@rnapier
Copy link

rnapier commented Apr 29, 2017

Previous ID SR-4736
Radar None
Original Reporter @rnapier
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 8.3.2

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, AcceptsInvalid, DefiniteInitialization
Assignee None
Priority Medium

md5: 03184d8a6cf438d233ec66793248256d

Issue Description:

The following code will crash when you instantiate (or in some cases use) C:

class S {
    let x: Int
    init(s: S) {
        self.x = s.x
    }
}

class C: S {
    init() {
        super.init(s: self)
    }
}

let c = C() // malloc: *** error for object 0x600000031244: Invalid pointer dequeued from free list

The compiler is allowing self to be passed to super.init, which should not be allowed.

If this is changed to init(s: AnyObject) (using type AnyObject rather than S), the compiler will generate the correct error. It seems specific to an init that accepts a parameter of the class's own type.

@slavapestov
Copy link
Member

This was fixed in Swift 4.0.

@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
accepts invalid Bug: Accepts invalid bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself definite initialization
Projects
None yet
Development

No branches or pull requests

2 participants