Skip to content

Commit 80a50c5

Browse files
authored
Merge pull request #29682 from slavapestov/self-diagnostic-spam-5.2
Sema: Fix duplicate diagnostic spam with 'Self' in properties [5.2]
2 parents dc46289 + 84f5cd8 commit 80a50c5

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,13 +1283,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
12831283
}
12841284

12851285
if (VD->getDeclContext()->getSelfClassDecl()) {
1286-
checkDynamicSelfType(VD, VD->getValueInterfaceType());
1287-
12881286
if (VD->getValueInterfaceType()->hasDynamicSelfType()) {
12891287
if (VD->hasStorage())
12901288
VD->diagnose(diag::dynamic_self_in_stored_property);
12911289
else if (VD->isSettable(nullptr))
12921290
VD->diagnose(diag::dynamic_self_in_mutable_property);
1291+
else
1292+
checkDynamicSelfType(VD, VD->getValueInterfaceType());
12931293
}
12941294
}
12951295

@@ -2098,8 +2098,11 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
20982098

20992099
checkExplicitAvailability(FD);
21002100

2101-
if (FD->getDeclContext()->getSelfClassDecl())
2102-
checkDynamicSelfType(FD, FD->getResultInterfaceType());
2101+
// Skip this for accessors, since we should have diagnosed the
2102+
// storage itself.
2103+
if (!isa<AccessorDecl>(FD))
2104+
if (FD->getDeclContext()->getSelfClassDecl())
2105+
checkDynamicSelfType(FD, FD->getResultInterfaceType());
21032106

21042107
checkDefaultArguments(FD->getParameters());
21052108

test/type/self.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,20 @@ class Foo {
270270
Self.value * 2
271271
}()
272272
}
273+
274+
// https://bugs.swift.org/browse/SR-11681 - duplicate diagnostics
275+
struct Box<T> {
276+
let boxed: T
277+
}
278+
279+
class Boxer {
280+
lazy var s = Box<Self>(boxed: self as! Self)
281+
// expected-error@-1 {{stored property cannot have covariant 'Self' type}}
282+
// expected-error@-2 {{mutable property cannot have covariant 'Self' type}}
283+
284+
var t = Box<Self>(boxed: Self())
285+
// expected-error@-1 {{stored property cannot have covariant 'Self' type}}
286+
// expected-error@-2 {{covariant 'Self' type cannot be referenced from a stored property initializer}}
287+
288+
required init() {}
289+
}

0 commit comments

Comments
 (0)