Skip to content

Commit 31d43bf

Browse files
author
Nathan Hawes
authored
Merge pull request #35508 from nathawes/fix-printsingledepthofgenericsignature-completion-crash
[CodeCompletion][ASTPrinter] Fix a null pointer dereference in PrintAST
2 parents d9cd7e7 + ee68f43 commit 31d43bf

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
735735
void printType(Type T) { printTypeWithOptions(T, Options); }
736736

737737
void printTransformedTypeWithOptions(Type T, PrintOptions options) {
738-
if (CurrentType) {
738+
if (CurrentType && Current) {
739739
if (T->hasArchetype()) {
740740
// Get the interface type, since TypeLocs still have
741741
// contextual types in them.
@@ -1527,7 +1527,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
15271527
(flags & SwapSelfAndDependentMemberType);
15281528

15291529
SubstitutionMap subMap;
1530-
if (CurrentType) {
1530+
if (CurrentType && Current) {
15311531
if (!CurrentType->isExistentialType()) {
15321532
auto *DC = Current->getInnermostDeclContext()->getInnermostTypeContext();
15331533
auto *M = DC->getParentModule();

test/IDE/complete_from_stdlib.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666

6767
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONFORM_SEQUENCE | %FileCheck %s -check-prefix=CONFORM_SEQUENCE
6868

69+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENERIC_CLOSUREARG | %FileCheck %s -check-prefix=GENERIC_CLOSUREARG
70+
6971
// NO_STDLIB_PRIVATE: Begin completions
7072
// NO_STDLIB_PRIVATE: End completions
7173

@@ -291,3 +293,13 @@ class TestSequence : Sequence {
291293
// CONFORM_SEQUENCE-DAG: Decl[InstanceMethod]/Super/IsSystem: func withContiguousStorageIfAvailable<R>(_ body: (UnsafeBufferPointer<Element>) throws -> R) rethrows -> R? {|};
292294
// CONFORM_SEQUENCE: End completions
293295
}
296+
297+
public func rdar_70057258<T>(_ f: T) {}
298+
extension Result {
299+
public init(_ value: Success?) {
300+
self = value.map(#^GENERIC_CLOSUREARG^#)
301+
}
302+
}
303+
// GENERIC_CLOSUREARG: Begin completions
304+
// GENERIC_CLOSUREARG: Decl[FreeFunction]/CurrModule/TypeRelation[Convertible]: rdar_70057258(_:)[#<T> (T) -> ()#]; name=rdar_70057258(_:)
305+
// GENERIC_CLOSUREARG: End completions

0 commit comments

Comments
 (0)