Skip to content

[CodeCompletion] Use substGenericArgs in getTypeOfMember #38447

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
3 changes: 2 additions & 1 deletion include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3503,7 +3503,8 @@ class GenericFunctionType final : public AnyFunctionType,

/// Substitute the given generic arguments into this generic
/// function type and return the resulting non-generic type.
FunctionType *substGenericArgs(SubstitutionMap subs);
FunctionType *substGenericArgs(SubstitutionMap subs,
SubstOptions options = None);
FunctionType *substGenericArgs(llvm::function_ref<Type(Type)> substFn) const;

void Profile(llvm::FoldingSetNodeID &ID) {
Expand Down
5 changes: 3 additions & 2 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3636,9 +3636,10 @@ bool SILFunctionType::hasSameExtInfoAs(const SILFunctionType *otherFn) {
}

FunctionType *
GenericFunctionType::substGenericArgs(SubstitutionMap subs) {
GenericFunctionType::substGenericArgs(SubstitutionMap subs,
SubstOptions options) {
return substGenericArgs(
[=](Type t) { return t.subst(subs); });
[=](Type t) { return t.subst(subs, options); });
}

FunctionType *GenericFunctionType::substGenericArgs(
Expand Down
13 changes: 10 additions & 3 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2601,9 +2601,16 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
// For everything else, substitute in the base type.
auto Subs = MaybeNominalType->getMemberSubstitutionMap(CurrModule, VD);

// Pass in DesugarMemberTypes so that we see the actual
// concrete type witnesses instead of type alias types.
T = T.subst(Subs, SubstFlags::DesugarMemberTypes);
// For a GenericFunctionType, we only want to substitute the
// param/result types, as otherwise we might end up with a bad generic
// signature if there are UnresolvedTypes present in the base type. Note
// we pass in DesugarMemberTypes so that we see the actual concrete type
// witnesses instead of type alias types.
if (auto *GFT = T->getAs<GenericFunctionType>()) {
T = GFT->substGenericArgs(Subs, SubstFlags::DesugarMemberTypes);
} else {
T = T.subst(Subs, SubstFlags::DesugarMemberTypes);
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions test/IDE/complete_crashes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,23 @@ struct StructWithCallAsFunction: HasCallAsFunctionRequirement {
}
// CRASH_CALL_AS_FUNCTION: Begin completion
// CRASH_CALL_AS_FUNCTION: End completions

// rdar://80635105
protocol P_80635105 {
associatedtype T
}
struct S_80635105<T> {}
extension S_80635105 : P_80635105 {}
extension P_80635105 {
func foo<U : P_80635105>(_ x: U.T) where U == Self.T {}
}

// RUN: %target-swift-ide-test -code-completion -code-completion-token=RDAR_80635105 -source-filename=%s | %FileCheck %s -check-prefix=RDAR_80635105
func test_80635105() {
let fn = { x in
S_80635105.#^RDAR_80635105^#
// RDAR_80635105: Begin completions
// RDAR_80635105: Decl[InstanceMethod]/Super: foo({#(self): S_80635105<_>#})[#(P_80635105.T) -> Void#]; name=foo
// RDAR_80635105: End completions
}
}