Skip to content

Commit 586aefd

Browse files
committed
Resolve SR-1397
1 parent f7353a7 commit 586aefd

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4598,11 +4598,18 @@ ConstructorDecl::getDelegatingOrChainedInitKind(DiagnosticEngine *diags,
45984598
return false;
45994599
}
46004600

4601+
bool walkToDeclPre(class Decl *D) override {
4602+
// Don't walk into further nominal decls.
4603+
if (isa<NominalTypeDecl>(D))
4604+
return false;
4605+
return true;
4606+
}
4607+
46014608
std::pair<bool, Expr*> walkToExprPre(Expr *E) override {
46024609
// Don't walk into closures.
46034610
if (isa<ClosureExpr>(E))
46044611
return { false, E };
4605-
4612+
46064613
// Look for calls of a constructor on self or super.
46074614
auto apply = dyn_cast<ApplyExpr>(E);
46084615
if (!apply)
@@ -4674,7 +4681,7 @@ ConstructorDecl::getDelegatingOrChainedInitKind(DiagnosticEngine *diags,
46744681
if (Kind == BodyInitKind::None && getAttrs().hasAttribute<ConvenienceAttr>())
46754682
Kind = BodyInitKind::Delegating;
46764683

4677-
// If wes till don't know, check whether we have a class with a superclass: it
4684+
// If we still don't know, check whether we have a class with a superclass: it
46784685
// gets an implicit chained initializer.
46794686
if (Kind == BodyInitKind::None) {
46804687
if (auto classDecl = getDeclContext()->getAsClassOrClassExtensionContext()) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %target-parse-verify-swift
2+
3+
class A {
4+
init() {}
5+
}
6+
7+
class B {
8+
init() {}
9+
10+
convenience init(x: ()) {
11+
class C: A {
12+
override init() { // No error
13+
super.init()
14+
}
15+
}
16+
17+
class D: A {
18+
convenience init(x: ()) {
19+
class DI : A {
20+
override init() { // No error
21+
super.init()
22+
}
23+
}
24+
25+
self.init()
26+
}
27+
28+
override init() { // No error
29+
class DI : A {
30+
override init() { // No error
31+
super.init()
32+
}
33+
}
34+
super.init()
35+
}
36+
}
37+
38+
struct E {
39+
init() {} // No error
40+
}
41+
42+
self.init()
43+
}
44+
}
45+

0 commit comments

Comments
 (0)