Skip to content

The compiler doesn't raise a compilation error for not calling the designated initializer #65316

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

Open
Gaoyanei opened this issue Apr 20, 2023 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@Gaoyanei
Copy link

Gaoyanei commented Apr 20, 2023

Description
The compiler doesn't raise a compilation error for not calling a designated initializer for a subclass of NSWindow if it has a let property.

Steps to reproduce

import AppKit
class AWindow: NSWindow {
    let name: String
    init(name: String) {
        self.name = name
        super.init() // Crashed when debugging: Use of unimplemented initializer 'init(contentRect:styleMask:backing:defer:)' 
    }
}`
_ = AWindow(name: "")

If I change var name to let name, the compiler raises the compilation error correctly.

class BWindow: NSWindow {
    var name: String
    init(name: String) {
        self.name = name
        super.init() // Compilation Error Must call a designated initializer of the superclass 'NSWindow'
    }
}
_ = BWindow(name: "")

Expected behavior
NSWindow should have only one initializer init(contentRect:styleMask:backing:defer:) marked as NS_DESIGNATED_INITIALIZER, so both AWindow and BWindow should raise compilation errors

image

Environment

  • Swift compiler version info: swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
    Target: arm64-apple-macosx13.0
  • Xcode version info: Xcode 14.2
    Build version 14C18
  • Deployment target: macOS 12.3
@Gaoyanei Gaoyanei added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Apr 20, 2023
@Gaoyanei Gaoyanei changed the title The compiler doesn't raise a compilation error for not calling a designated initializer The compiler doesn't raise a compilation error for not calling the designated initializer Apr 20, 2023
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. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant