Skip to content

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

@Gaoyanei

Description

@Gaoyanei

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions