diff --git a/lib/Sema/TypeOfReference.cpp b/lib/Sema/TypeOfReference.cpp index cace6723c974b..e504b4b4444db 100644 --- a/lib/Sema/TypeOfReference.cpp +++ b/lib/Sema/TypeOfReference.cpp @@ -279,6 +279,19 @@ class InferableTypeOpener final { return PlaceholderType::get(cs.getASTContext(), errTy); } + Type transformDependentMemberType(DependentMemberType *DMT) { + auto assocTy = DMT->getAssocType(); + ASSERT(assocTy && "Should not have structural type here"); + + // If the new base is a hole, propagate it to cover the entire + // DependentMemberType. + auto newBase = transform(DMT->getBase()); + if (newBase->isPlaceholder()) + return PlaceholderType::get(cs.getASTContext(), DMT); + + return DependentMemberType::get(newBase, assocTy); + } + Type transform(Type type) { if (!type) return type; @@ -308,6 +321,8 @@ class InferableTypeOpener final { return transformTypeAliasType(aliasTy); if (auto *errTy = dyn_cast(tyPtr)) return transformErrorType(errTy); + if (auto *DMT = dyn_cast(tyPtr)) + return transformDependentMemberType(DMT); return std::nullopt; }); diff --git a/validation-test/compiler_crashers_2_fixed/a8575b8261697c42.swift b/validation-test/compiler_crashers_2_fixed/a8575b8261697c42.swift new file mode 100644 index 0000000000000..2de09f6c8b30d --- /dev/null +++ b/validation-test/compiler_crashers_2_fixed/a8575b8261697c42.swift @@ -0,0 +1,4 @@ +// {"kind":"typecheck","original":"9e6249db","signature":"(anonymous namespace)::ConstraintGenerator::visitApplyExpr(swift::ApplyExpr*)"} +// RUN: not %target-swift-frontend -typecheck %s +(a as Sequence).Element { +} diff --git a/validation-test/compiler_crashers_2_fixed/fddb1549773c253.swift b/validation-test/compiler_crashers_2_fixed/fddb1549773c253.swift new file mode 100644 index 0000000000000..0242b2657331a --- /dev/null +++ b/validation-test/compiler_crashers_2_fixed/fddb1549773c253.swift @@ -0,0 +1,7 @@ +// {"kind":"typecheck","original":"5e6f691d","signature":"(anonymous namespace)::ConstraintGenerator::visitApplyExpr(swift::ApplyExpr*)"} +// RUN: not %target-swift-frontend -typecheck %s +protocol a { + associatedtype b + struct c