Skip to content

Subclass compiles without initializing properties #69965

Open
@PadraigK

Description

@PadraigK

Description

When subclassing an open class from another module, Swift is not warning me if I have neglect to initialize all properties in my subclass. It unexpectedly builds fine but crashes at runtime.

Steps to reproduce

ModuleA:

open class MySuperclass {}

ModuleB:

import ModuleA
class MySubclass: MySuperclass {
    var hi: String
}

hi is never initialized, but this builds.

Expected behavior
I expect an error like: Class 'MySubclass' has no initializers: Stored property 'hi' without initial value prevents synthesized initializers. If I remove the inheritance clause from MySubclass I do get this error.

Environment

  • swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
    Target: arm64-apple-macosx14.0
  • Xcode 15.0.1 / 15A507
  • Deployment target: macOS 13

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