Files
swift-mirror/test/ModuleInterface/inherited-objc-superclass-initializers.swift
Allan Shortlidge 6c1fe8137a Sema: Allow some references to declarations that are unavailable-in-Swift.
Swift generates implicit constructors for inherited designated initializers in
case some implicit initialization (such as running property initializer
expressions) needs to run after calling the initializer on the superclass.
These implicit initializers are printed in .swiftinterfaces and previously they
could cause the interface to fail to typecheck when one of the parameters is
declared to be unavailable-in-Swift. These initializers need to be generated
because they may be called from Objective-C where the unavailable-in-Swift
designation is irrelevant. To account for this possibility, relax availability
checking to allow this narrow exception only in .swiftinterfaces.

Another possible but more complicated solution would be to print the
initializers with an attribute that indicates that the initializer is inherited
and implicit. This would allow the typechecking exception to be more precise
but seems unnecessarily complicated given that the exception is only needed in
.swiftinterfaces, which are already compiler generated.

Resolves rdar://77221357
2024-01-03 19:36:16 -08:00

22 lines
1.0 KiB
Swift

// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -I %S/Inputs/inherited-objc-initializers/ -module-name Test
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -I %S/Inputs/inherited-objc-initializers/ -module-name Test
// RUN: %FileCheck %s < %t.swiftinterface
// REQUIRES: objc_interop
import InheritedObjCInits
// CHECK: @objc @_inheritsConvenienceInitializers public class Subclass2 : InheritedObjCInits.HasAvailableInit {
public class Subclass2: HasAvailableInit {
// CHECK-NEXT: @objc override dynamic public init(unavailable: InheritedObjCInits.UnavailableInSwift)
// CHECK-NEXT: @objc override dynamic public init()
// CHECK-NEXT: @objc deinit
} // CHECK-NEXT:{{^}$}}
// CHECK: @objc @_inheritsConvenienceInitializers public class Subclass1 : InheritedObjCInits.HasUnavailableInit {
public class Subclass1: HasUnavailableInit {
// CHECK-NOT: InheritedObjCInits.UnavailableInSwift
// CHECK-NEXT: @objc override dynamic public init()
// CHECK-NEXT: @objc deinit
} // CHECK-NEXT:{{^}$}}