Skip to content

Commit d43c515

Browse files
committed
[Property wrappers] Reject opaque result types when there is no initializer.
Fixes rdar://problem/63169705 / FB7699647.
1 parent 932a91e commit d43c515

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,6 +2693,10 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
26932693
initializer);
26942694
pbd->setInit(0, initializer);
26952695
pbd->setInitializerChecked(0);
2696+
2697+
if (var->getOpaqueResultTypeDecl()) {
2698+
var->diagnose(diag::opaque_type_var_no_underlying_type);
2699+
}
26962700
}
26972701

26982702
// If there is a projection property (projectedValue) in the wrapper,

test/decl/var/property_wrappers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1972,4 +1972,4 @@ public struct NonVisibleImplicitInit {
19721972
public var wrappedValue: Bool {
19731973
return false
19741974
}
1975-
}
1975+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 5 -disable-availability-checking
2+
3+
protocol P { }
4+
5+
@propertyWrapper
6+
struct WrapperWithDefaultInit<T> {
7+
private var stored: T?
8+
9+
var wrappedValue: T {
10+
get { stored! }
11+
set { stored = newValue }
12+
}
13+
14+
init() {
15+
self.stored = nil
16+
}
17+
}
18+
19+
// FB7699647 - crash with opaque result type and property wrappers.
20+
struct FB7699647 {
21+
@WrapperWithDefaultInit var property: some P // expected-error{{property declares an opaque return type, but cannot infer the underlying type from its initializer expression}}
22+
@WrapperWithDefaultInit() var otherProperty: some P // expected-error{{property declares an opaque return type, but cannot infer the underlying type from its initializer expression}}
23+
}
24+

0 commit comments

Comments
 (0)