Skip to content

Commit eb3f288

Browse files
committed
[Property delegates] Fix textual interfaces for properties with delegates
Don’t synthesize a missing setter for a property that has an attached delegate and is in a .swiftinterface file.
1 parent 7092be6 commit eb3f288

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,11 +1771,14 @@ static void maybeAddAccessorsForPropertyDelegate(VarDecl *var,
17711771
auto valueVar = var->getAttachedPropertyDelegateTypeInfo().valueVar;
17721772
assert(valueVar && "Cannot fail when the backing var is valid");
17731773

1774+
auto parentSF = var->getDeclContext()->getParentSourceFile();
17741775
bool delegateSetterIsUsable =
17751776
var->getSetter() ||
1776-
(!var->isLet() &&
1777-
valueVar->isSettable(nullptr) &&
1778-
valueVar->isSetterAccessibleFrom(var->getInnermostDeclContext()));
1777+
(parentSF &&
1778+
parentSF->Kind != SourceFileKind::Interface &&
1779+
!var->isLet() &&
1780+
valueVar->isSettable(nullptr) &&
1781+
valueVar->isSetterAccessibleFrom(var->getInnermostDeclContext()));
17791782

17801783
if (!var->getGetter()) {
17811784
addGetterToStorage(var, ctx);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -typecheck -swift-version 5 -module-name TestResilient -emit-parseable-module-interface-path %t/TestResilient.swiftinterface -enable-library-evolution %s
4+
// RUN: %FileCheck %s < %t/TestResilient.swiftinterface --check-prefix CHECK --check-prefix RESILIENT
5+
6+
// RUN: %target-swift-frontend -build-module-from-parseable-interface -swift-version 5 %t/TestResilient.swiftinterface -o %t/TestResilient.swiftmodule
7+
// RUN: %target-swift-frontend -emit-module -o /dev/null -merge-modules -swift-version 5 -emit-parseable-module-interface-path - %t/TestResilient.swiftmodule -module-name TestResilient | %FileCheck %s --check-prefix CHECK --check-prefix RESILIENT
8+
9+
@_propertyDelegate
10+
public struct Wrapper<T> {
11+
public var value: T
12+
}
13+
14+
@_propertyDelegate
15+
public struct WrapperWithInitialValue<T> {
16+
public var value: T
17+
18+
public init(initialValue: T) {
19+
self.value = initialValue
20+
}
21+
22+
public init(alternate value: T) {
23+
self.value = value
24+
}
25+
}
26+
27+
// CHECK: public struct HasDelegates {
28+
public struct HasDelegates {
29+
// CHECK: @TestResilient.Wrapper public var x: {{(Swift.)?}}Int {
30+
// CHECK-NEXT: get
31+
// CHECK-NEXT: set
32+
// CHECK-NEXT: }
33+
@Wrapper public var x: Int
34+
35+
// CHECK: @TestResilient.WrapperWithInitialValue public var y: Swift.Int {
36+
// CHECK-NEXT: get
37+
// CHECK-NEXT: }
38+
@WrapperWithInitialValue public private(set) var y = 17
39+
40+
// CHECK: @TestResilient.WrapperWithInitialValue public var z: Swift.Bool {
41+
// CHECK-NEXT: get
42+
// CHECK-NEXT: set
43+
// CHECK-NEXT: }
44+
@WrapperWithInitialValue(alternate: false) public var z
45+
}

0 commit comments

Comments
 (0)