Skip to content

Commit 0db4b43

Browse files
Merge pull request #61863 from LucianoPAlmeida/crash-dump-parse-init
[ASTDumper] Special handling for init kind in pre-typecheck dump
2 parents dfe6fd9 + 70b884c commit 0db4b43

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
@@ -9089,6 +9089,20 @@ Type ConstructorDecl::getInitializerInterfaceType() {
90899089
}
90909090

90919091
CtorInitializerKind ConstructorDecl::getInitKind() const {
9092+
const auto *ED =
9093+
dyn_cast_or_null<ExtensionDecl>(getDeclContext()->getAsDecl());
9094+
if (ED && !ED->hasBeenBound()) {
9095+
// When the declaration context is an extension and this is called when the
9096+
// extended nominal hasn't be bound yet, e.g. dumping pre-typechecked AST,
9097+
// there is not enough information about extended nominal to use for
9098+
// computing init kind on InitKindRequest as bindExtensions is done at
9099+
// typechecking, so in that case just look to parsed attribute in init
9100+
// declaration.
9101+
return getAttrs().hasAttribute<ConvenienceAttr>()
9102+
? CtorInitializerKind::Convenience
9103+
: CtorInitializerKind::Designated;
9104+
}
9105+
90929106
return evaluateOrDefault(getASTContext().evaluator,
90939107
InitKindRequest{const_cast<ConstructorDecl *>(this)},
90949108
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)