Skip to content

Commit 70b884c

Browse files
[ASTDumper] Special handling for init kind in pre-typecheck dump
1 parent 98dc1d5 commit 70b884c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/AST/Decl.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9104,6 +9104,20 @@ Type ConstructorDecl::getInitializerInterfaceType() {
91049104
}
91059105

91069106
CtorInitializerKind ConstructorDecl::getInitKind() const {
9107+
const auto *ED =
9108+
dyn_cast_or_null<ExtensionDecl>(getDeclContext()->getAsDecl());
9109+
if (ED && !ED->hasBeenBound()) {
9110+
// When the declaration context is an extension and this is called when the
9111+
// extended nominal hasn't be bound yet, e.g. dumping pre-typechecked AST,
9112+
// there is not enough information about extended nominal to use for
9113+
// computing init kind on InitKindRequest as bindExtensions is done at
9114+
// typechecking, so in that case just look to parsed attribute in init
9115+
// declaration.
9116+
return getAttrs().hasAttribute<ConvenienceAttr>()
9117+
? CtorInitializerKind::Convenience
9118+
: CtorInitializerKind::Designated;
9119+
}
9120+
91079121
return evaluateOrDefault(getASTContext().evaluator,
91089122
InitKindRequest{const_cast<ConstructorDecl *>(this)},
91099123
CtorInitializerKind::Designated);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-typecheck-verify-swift -dump-parse
2+
3+
// https://github.com/apple/swift/issues/61806
4+
5+
struct I61806 {}
6+
extension I61806 {
7+
init() { }
8+
}
9+
10+
class I61806_C {
11+
init() {}
12+
}
13+
extension I61806_C {
14+
convenience init(a: Int) {}
15+
}
16+
17+
protocol I61806_P {}
18+
extension I61806_P {
19+
init() {}
20+
}

0 commit comments

Comments
 (0)