Skip to content

Swift 6 regression overriding initializers due to Swift Concurrency #75732

@NachoSoto

Description

@NachoSoto

Description

It used to be possible to override a class like UIView/NSView to provide a new designated initializer that delegated to the parent's designated initializer. It no longer is with swiftlang-6.0.0.7.6.

Reproduction

class A: NSView {
  // Call to main actor-isolated initializer 'init(frame:)' in a synchronous nonisolated context
  init() {
    super.init(frame: .zero)
  }

  // It's 2024 and I still have to write this lol but anyway that's not what this bug is about
  required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
}

Expected behavior

This compiles like it's done for many versions of Swift.

Actual behavior:

Call to main actor-isolated initializer 'init(frame:)' in a synchronous nonisolated context

No other variant works either:

class A: NSView {
  // Main actor-isolated initializer 'init()' has different actor isolation from nonisolated overridden declaration
  @MainActor
  init() {
    super.init(frame: .zero)
  }

  required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
}

This one is particularly puzzling. Why would init() on a @MainActor type be nonisolated? This seems like a serious regression too:

@MainActor
class A: NSView {
  init() {
    // Call to main actor-isolated initializer 'init(frame:)' in a synchronous nonisolated context
    super.init(frame: .zero)
  }

  required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
}

Environment

swift-driver version: 1.113 Apple Swift version 6.0 (swiftlang-6.0.0.7.6 clang-1600.0.24.1)
Target: arm64-apple-macosx14.0

Additional information

It's also completely impossible to figure out what actor isolation the class / constructors have. CMD+Click on Xcode to show the interface does not show any actor isolation information:

Screenshot 2024-08-06 at 14 53 28

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.concurrencyFeature: umbrella label for concurrency language features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions