Skip to content

Commit 1ead8ea

Browse files
committed
Sema: Stored properties cannot have DynamicSelfType
1 parent bf8e50c commit 1ead8ea

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,6 +2581,8 @@ ERROR(dynamic_self_invalid,none,
25812581
"did you mean '%0'?", (StringRef))
25822582
ERROR(dynamic_self_in_mutable_property,none,
25832583
"mutable property cannot have covariant 'Self' type", ())
2584+
ERROR(dynamic_self_in_stored_property,none,
2585+
"stored property cannot have covariant 'Self' type", ())
25842586
ERROR(dynamic_self_in_mutable_subscript,none,
25852587
"mutable subscript cannot have covariant 'Self' type", ())
25862588
ERROR(dynamic_self_invalid_property,none,

lib/Sema/TypeCheckDecl.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,9 +2376,11 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
23762376
if (VD->getDeclContext()->getSelfClassDecl()) {
23772377
checkDynamicSelfType(VD, VD->getValueInterfaceType());
23782378

2379-
if (VD->getValueInterfaceType()->hasDynamicSelfType() &&
2380-
VD->isSettable(nullptr)) {
2381-
VD->diagnose(diag::dynamic_self_in_mutable_property);
2379+
if (VD->getValueInterfaceType()->hasDynamicSelfType()) {
2380+
if (VD->hasStorage())
2381+
VD->diagnose(diag::dynamic_self_in_stored_property);
2382+
else if (VD->isSettable(nullptr))
2383+
VD->diagnose(diag::dynamic_self_in_mutable_property);
23822384
}
23832385
}
23842386

test/type/self.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,11 @@ class C {
139139
func j() -> Self.Type {}
140140
// expected-error@-1 {{covariant 'Self' can only appear at the top level of method result type}}
141141

142-
let p0: Self?
143-
var p1: Self? // expected-error {{mutable property cannot have covariant 'Self' type}}
142+
let p0: Self? // expected-error {{stored property cannot have covariant 'Self' type}}
143+
var p1: Self? // expected-error {{stored property cannot have covariant 'Self' type}}
144+
145+
static func staticFunc() -> Self {}
146+
let stored: Self = Self.staticFunc() // expected-error {{stored property cannot have covariant 'Self' type}}
144147

145148
var prop: Self { // expected-error {{mutable property cannot have covariant 'Self' type}}
146149
get {

0 commit comments

Comments
 (0)