Skip to content

Commit 52c1fd8

Browse files
[ASTDumper] Special handling for init kind in pre-typecheck dump
1 parent 9a9cfab commit 52c1fd8

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/AST/ASTDumper.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,8 +1174,23 @@ namespace {
11741174
printCommonAFD(CD, "constructor_decl");
11751175
if (CD->isRequired())
11761176
PrintWithColorRAII(OS, DeclModifierColor) << " required";
1177-
PrintWithColorRAII(OS, DeclModifierColor) << " "
1178-
<< getCtorInitializerKindString(CD->getInitKind());
1177+
1178+
CtorInitializerKind kind;
1179+
const auto *ED =
1180+
dyn_cast_or_null<ExtensionDecl>(CD->getDeclContext()->getAsDecl());
1181+
if (ED && !ED->hasBeenBound()) {
1182+
// When dumping pre-typechecked AST there is not enough information
1183+
// about extended nominal to use for computing init kind as
1184+
// bindExtensions is done at typechecking, so in that case just look to
1185+
// parsed attribute in init declaration.
1186+
kind = CD->getAttrs().hasAttribute<ConvenienceAttr>()
1187+
? CtorInitializerKind::Convenience
1188+
: CtorInitializerKind::Designated;
1189+
} else {
1190+
kind = CD->getInitKind();
1191+
}
1192+
PrintWithColorRAII(OS, DeclModifierColor)
1193+
<< " " << getCtorInitializerKindString(kind);
11791194
if (CD->isFailable())
11801195
PrintWithColorRAII(OS, DeclModifierColor) << " failable="
11811196
<< (CD->isImplicitlyUnwrappedOptional()
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)