Skip to content

[5.1] Cherry-pick module interface fixes to 5.1 #24250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,13 @@ void AttributeEarlyChecker::visitIBOutletAttr(IBOutletAttr *attr) {
if (!VD->getDeclContext()->getSelfClassDecl() || VD->isStatic())
diagnoseAndRemoveAttr(attr, diag::invalid_iboutlet);

if (!VD->isSettable(nullptr))
diagnoseAndRemoveAttr(attr, diag::iboutlet_only_mutable);
if (!VD->isSettable(nullptr)) {
// Allow non-mutable IBOutlet properties in module interfaces,
// as they may have been private(set)
SourceFile *Parent = VD->getDeclContext()->getParentSourceFile();
if (!Parent || Parent->Kind != SourceFileKind::Interface)
diagnoseAndRemoveAttr(attr, diag::iboutlet_only_mutable);
}

// Verify that the field type is valid as an outlet.
auto type = VD->getType();
Expand Down
5 changes: 4 additions & 1 deletion lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2613,7 +2613,10 @@ class swift::DeclDeserializer {
if (auto *overridden = ctor->getOverriddenDecl()) {
if (!attributeChainContains<RequiredAttr>(DAttrs) ||
!overridden->isRequired()) {
AddAttribute(new (ctx) OverrideAttr(SourceLoc()));
// FIXME: why is a convenience init considered overridden when the
// overriding init can't be marked overriding in source?
if (!overridden->isConvenienceInit())
AddAttribute(new (ctx) OverrideAttr(SourceLoc()));
}
}

Expand Down
51 changes: 51 additions & 0 deletions test/ParseableInterface/convenience-init.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// RUN: %empty-directory(%t)

// Generate the parseable interface of the current file via the merge-modules step
// RUN: %target-build-swift -emit-module -o %t/Test.swiftmodule -emit-parseable-module-interface-path %t/TestMerge.swiftinterface -module-name Test %s

// Generate the parseable interface of the current file via a single frontend invocation
// RUN: %target-swift-frontend -typecheck -enable-objc-interop -emit-parseable-module-interface-path %t/TestSingle.swiftinterface -module-name Test %s

// Make sure both don't add override for inits shadowing convenience initializers
// RUN: %FileCheck --check-prefixes=CHECK,SINGLE %s < %t/TestSingle.swiftinterface
// RUN: %FileCheck --check-prefixes=CHECK,MERGE %s < %t/TestMerge.swiftinterface

// Check we can consume the interface without issue
// RUN: %target-swift-frontend -swift-version 5 -build-module-from-parseable-interface -o %t/Test.swiftmodule %t/TestSingle.swiftinterface
// RUN: %target-swift-frontend -swift-version 5 -build-module-from-parseable-interface -o %t/Test.swiftmodule %t/TestMerge.swiftinterface

public class Base {
let x: Int
public init(x: Int) {
self.x = x
}
convenience public init() {
self.init(x: 1)
}
}

public class Derived: Base {
// MERGE: {{^}} public init(z: Swift.Int)
// SINGLE: {{^}} public init(z: Int)
public init(z: Int) {
super.init(x: z)
}
// MERGE: {{^}} public convenience init()
// SINGLE: {{^}} convenience public init()
convenience public init() {
self.init(z: 1)
}
}

public class Derived2: Base {
// CHECK: {{^}} public init()
public init() {
super.init(x: 1)
}

// MERGE: {{^}} override public convenience init(x: Swift.Int)
// SINGLE: {{^}} override convenience public init(x: Int)
override convenience public init(x: Int) {
self.init()
}
}
18 changes: 18 additions & 0 deletions test/ParseableInterface/iboutlet-private-set.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// REQUIRES: objc_interop

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -typecheck -enable-library-evolution -disable-objc-attr-requires-foundation-module -emit-parseable-module-interface-path %t/Foo.swiftinterface %s
// RUN: %FileCheck %s -input-file %t/Foo.swiftinterface
// RUN: %target-swift-frontend -build-module-from-parseable-interface %t/Foo.swiftinterface -o %t/Foo.swiftmodule

// Test the interface we generate for @IBOutlet private(set) properties is
// consumable.

@objc public class MyType {}

open class Bar {
// CHECK: @objc @IBOutlet weak public var foo: MyType! {
// CHECK-NEXT: get
// CHECK-NEXT: }
@IBOutlet public private(set) weak var foo: MyType!
}