Skip to content

Commit 6761d84

Browse files
authored
Merge pull request #84273 from hamishknight/the-whole-hole
[CS] Avoid forming DependentMemberType with hole base in `InferableTypeOpener`
2 parents 411e14d + 0f7490a commit 6761d84

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

lib/Sema/TypeOfReference.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,19 @@ class InferableTypeOpener final {
279279
return PlaceholderType::get(cs.getASTContext(), errTy);
280280
}
281281

282+
Type transformDependentMemberType(DependentMemberType *DMT) {
283+
auto assocTy = DMT->getAssocType();
284+
ASSERT(assocTy && "Should not have structural type here");
285+
286+
// If the new base is a hole, propagate it to cover the entire
287+
// DependentMemberType.
288+
auto newBase = transform(DMT->getBase());
289+
if (newBase->isPlaceholder())
290+
return PlaceholderType::get(cs.getASTContext(), DMT);
291+
292+
return DependentMemberType::get(newBase, assocTy);
293+
}
294+
282295
Type transform(Type type) {
283296
if (!type)
284297
return type;
@@ -308,6 +321,8 @@ class InferableTypeOpener final {
308321
return transformTypeAliasType(aliasTy);
309322
if (auto *errTy = dyn_cast<ErrorType>(tyPtr))
310323
return transformErrorType(errTy);
324+
if (auto *DMT = dyn_cast<DependentMemberType>(tyPtr))
325+
return transformDependentMemberType(DMT);
311326

312327
return std::nullopt;
313328
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// {"kind":"typecheck","original":"9e6249db","signature":"(anonymous namespace)::ConstraintGenerator::visitApplyExpr(swift::ApplyExpr*)"}
2+
// RUN: not %target-swift-frontend -typecheck %s
3+
(a as Sequence).Element {
4+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// {"kind":"typecheck","original":"5e6f691d","signature":"(anonymous namespace)::ConstraintGenerator::visitApplyExpr(swift::ApplyExpr*)"}
2+
// RUN: not %target-swift-frontend -typecheck %s
3+
protocol a {
4+
associatedtype b
5+
struct c<d, a {
6+
e {
7+
d.b {

0 commit comments

Comments
 (0)