Closed
Description
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