Skip to content

[ASTDumper] Special handling for init kind in pre-typecheck dump #61863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9104,6 +9104,20 @@ Type ConstructorDecl::getInitializerInterfaceType() {
}

CtorInitializerKind ConstructorDecl::getInitKind() const {
const auto *ED =
dyn_cast_or_null<ExtensionDecl>(getDeclContext()->getAsDecl());
if (ED && !ED->hasBeenBound()) {
// When the declaration context is an extension and this is called when the
// extended nominal hasn't be bound yet, e.g. dumping pre-typechecked AST,
// there is not enough information about extended nominal to use for
// computing init kind on InitKindRequest as bindExtensions is done at
// typechecking, so in that case just look to parsed attribute in init
// declaration.
return getAttrs().hasAttribute<ConvenienceAttr>()
? CtorInitializerKind::Convenience
: CtorInitializerKind::Designated;
}

return evaluateOrDefault(getASTContext().evaluator,
InitKindRequest{const_cast<ConstructorDecl *>(this)},
CtorInitializerKind::Designated);
Expand Down
20 changes: 20 additions & 0 deletions validation-test/compiler_crashers_2_fixed/issue-61086.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %target-typecheck-verify-swift -dump-parse

// https://github.com/apple/swift/issues/61806

struct I61806 {}
extension I61806 {
init() { }
}

class I61806_C {
init() {}
}
extension I61806_C {
convenience init(a: Int) {}
}

protocol I61806_P {}
extension I61806_P {
init() {}
}