Skip to content

[CodeCompletion][ASTPrinter] Fix a null pointer dereference in PrintAST #35508

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
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
4 changes: 2 additions & 2 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
void printType(Type T) { printTypeWithOptions(T, Options); }

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

SubstitutionMap subMap;
if (CurrentType) {
if (CurrentType && Current) {
if (!CurrentType->isExistentialType()) {
auto *DC = Current->getInnermostDeclContext()->getInnermostTypeContext();
auto *M = DC->getParentModule();
Expand Down
12 changes: 12 additions & 0 deletions test/IDE/complete_from_stdlib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@

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

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

// NO_STDLIB_PRIVATE: Begin completions
// NO_STDLIB_PRIVATE: End completions

Expand Down Expand Up @@ -291,3 +293,13 @@ class TestSequence : Sequence {
// CONFORM_SEQUENCE-DAG: Decl[InstanceMethod]/Super/IsSystem: func withContiguousStorageIfAvailable<R>(_ body: (UnsafeBufferPointer<Element>) throws -> R) rethrows -> R? {|};
// CONFORM_SEQUENCE: End completions
}

public func rdar_70057258<T>(_ f: T) {}
extension Result {
public init(_ value: Success?) {
self = value.map(#^GENERIC_CLOSUREARG^#)
}
}
// GENERIC_CLOSUREARG: Begin completions
// GENERIC_CLOSUREARG: Decl[FreeFunction]/CurrModule/TypeRelation[Convertible]: rdar_70057258(_:)[#<T> (T) -> ()#]; name=rdar_70057258(_:)
// GENERIC_CLOSUREARG: End completions