Skip to content

adding global actor erroneously allowed when overriding an ObjC class's method #72238

Closed
@KeithBauerANZ

Description

@KeithBauerANZ

Description

Normally, you can't add a global actor annotation when overriding a method (obviously!); this is disallowed:

class Base {
    func a() {}
}

class Inherited: Base {
    @MainActor
    override func a() {}
}
MainActorOverride.swift:7:19: error: main actor-isolated instance method 'a()' has different actor isolation from nonisolated overridden declaration
    override func a() {}
                  ^
MainActorOverride.swift:2:10: note: overridden declaration is here
    func a() {}
         ^

However, when the method being overridden is from an Objective-C class, this is erroneously allowed.

Reproduction

import Foundation

class Inherited: UserDefaults {
    @MainActor
    override func object(forKey: String) -> Any? {
        nil
    }
}

Expected behavior

The override of object(forKey:) should produce the same error as the override of a in the initial example.

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    actor isolationFeature → concurrency: Actor isolationbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.concurrencyFeature: umbrella label for concurrency language featuresdeclarationsFeature: declarationstype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions