Skip to content

Commit 0911d2d

Browse files
committed
[Property wrappers] Reject opaque result types when there is no initializer.
Fixes rdar://problem/63169705 / FB7699647. (cherry picked from commit d43c515)
1 parent 1ebb558 commit 0911d2d

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
@@ -2694,6 +2694,10 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
26942694
initializer);
26952695
pbd->setInit(0, initializer);
26962696
pbd->setInitializerChecked(0);
2697+
2698+
if (var->getOpaqueResultTypeDecl()) {
2699+
var->diagnose(diag::opaque_type_var_no_underlying_type);
2700+
}
26972701
}
26982702

26992703
// 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)