Skip to content

Commit 63c6f98

Browse files
authored
Merge pull request #38447 from hamishknight/fewer-substitutions-for-you
2 parents ba4024f + f90befe commit 63c6f98

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

include/swift/AST/Types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3503,7 +3503,8 @@ class GenericFunctionType final : public AnyFunctionType,
35033503

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

35093510
void Profile(llvm::FoldingSetNodeID &ID) {

lib/AST/Type.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3636,9 +3636,10 @@ bool SILFunctionType::hasSameExtInfoAs(const SILFunctionType *otherFn) {
36363636
}
36373637

36383638
FunctionType *
3639-
GenericFunctionType::substGenericArgs(SubstitutionMap subs) {
3639+
GenericFunctionType::substGenericArgs(SubstitutionMap subs,
3640+
SubstOptions options) {
36403641
return substGenericArgs(
3641-
[=](Type t) { return t.subst(subs); });
3642+
[=](Type t) { return t.subst(subs, options); });
36423643
}
36433644

36443645
FunctionType *GenericFunctionType::substGenericArgs(

lib/IDE/CodeCompletion.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,9 +2563,16 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
25632563
// For everything else, substitute in the base type.
25642564
auto Subs = MaybeNominalType->getMemberSubstitutionMap(CurrModule, VD);
25652565

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

test/IDE/complete_crashes.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,23 @@ struct StructWithCallAsFunction: HasCallAsFunctionRequirement {
389389
}
390390
// CRASH_CALL_AS_FUNCTION: Begin completion
391391
// CRASH_CALL_AS_FUNCTION: End completions
392+
393+
// rdar://80635105
394+
protocol P_80635105 {
395+
associatedtype T
396+
}
397+
struct S_80635105<T> {}
398+
extension S_80635105 : P_80635105 {}
399+
extension P_80635105 {
400+
func foo<U : P_80635105>(_ x: U.T) where U == Self.T {}
401+
}
402+
403+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=RDAR_80635105 -source-filename=%s | %FileCheck %s -check-prefix=RDAR_80635105
404+
func test_80635105() {
405+
let fn = { x in
406+
S_80635105.#^RDAR_80635105^#
407+
// RDAR_80635105: Begin completions
408+
// RDAR_80635105: Decl[InstanceMethod]/Super: foo({#(self): S_80635105<_>#})[#(P_80635105.T) -> Void#]; name=foo
409+
// RDAR_80635105: End completions
410+
}
411+
}

0 commit comments

Comments
 (0)