Skip to content

Commit db49faf

Browse files
committed
[Sema] Avoid solver-allocated original ErrorTypes in transformDependentMemberType
`substBase` here can contain type variables or placeholders, avoid using them as the original ErrorTypes since ErrorTypes cannot be solver-allocated currently. This only affects type printing so shouldn't matter much.
1 parent 6d0da8d commit db49faf

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/AST/TypeSubstitution.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,13 @@ Type TypeSubstituter::transformDependentMemberType(DependentMemberType *dependen
446446

447447
auto result = conformance.getTypeWitness(assocType, IFS.getOptions());
448448
if (result->is<ErrorType>()) {
449+
// Substitute the base type for the original ErrorType for type printing.
450+
// Avoid doing this if the substitutions introduce type variables or
451+
// placeholders since ErrorTypes can't be solver-allocated currently (and
452+
// type variables aren't helpful when printing anyway).
449453
auto substBase = origBase.subst(IFS);
450-
return DependentMemberType::get(ErrorType::get(substBase), assocType);
454+
if (!substBase->hasTypeVariableOrPlaceholder())
455+
return DependentMemberType::get(ErrorType::get(substBase), assocType);
451456
}
452457
return result;
453458
}
@@ -1242,4 +1247,4 @@ ProtocolConformanceRef ReplaceExistentialArchetypesWithConcreteTypes::operator()
12421247

12431248
return subs.lookupConformance(
12441249
getInterfaceType(existentialArchetype)->getCanonicalType(), proto);
1245-
}
1250+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=COMPLETE -source-filename=%s
2+
3+
// https://github.com/swiftlang/swift/pull/82147
4+
5+
protocol P {
6+
associatedtype X
7+
}
8+
9+
struct S<T> {
10+
init<U, V>() where T == (U, V) {}
11+
}
12+
extension S : P where T : P {
13+
typealias X = T.X
14+
}
15+
16+
func foo<T: P, U>(_: () -> T) where U == T.X {}
17+
18+
foo {
19+
S(#^COMPLETE^#)
20+
}

0 commit comments

Comments
 (0)