Skip to content

Commit aa9aa58

Browse files
committed
[Sema] Handle PlaceholderTypes in associated type inference
Avoid attempting to infer an associatedtype as a type that contains placeholders.
1 parent d1b8084 commit aa9aa58

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

include/swift/AST/TypeMatcher.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ class TypeMatcher {
117117
#define SINGLETON_TYPE(SHORT_ID, ID) TRIVIAL_CASE(ID##Type)
118118
#include "swift/AST/TypeNodes.def"
119119

120+
bool visitPlaceholderType(CanPlaceholderType firstType, Type secondType,
121+
Type sugaredFirstType) {
122+
// Placeholder types never match.
123+
return mismatch(firstType.getPointer(), secondType, sugaredFirstType);
124+
}
125+
120126
bool visitUnresolvedType(CanUnresolvedType firstType, Type secondType,
121127
Type sugaredFirstType) {
122128
// Unresolved types never match.

lib/Sema/AssociatedTypeInference.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,9 +2317,9 @@ AssociatedTypeInference::getPotentialTypeWitnessesByMatchingTypes(ValueDecl *req
23172317
/// Deduce associated types from dependent member types in the witness.
23182318
bool mismatch(DependentMemberType *firstDepMember,
23192319
TypeBase *secondType, Type sugaredFirstType) {
2320-
// If the second type is an error, don't look at it further, but proceed
2321-
// to find other matches.
2322-
if (secondType->hasError())
2320+
// If the second type is an error or placeholder, don't look at it
2321+
// further, but proceed to find other matches.
2322+
if (secondType->hasError() || secondType->hasPlaceholder())
23232323
return true;
23242324

23252325
// If the second type is a generic parameter of the witness, the match

validation-test/compiler_crashers_2/ac7123f2338b128.swift renamed to validation-test/compiler_crashers_2_fixed/ac7123f2338b128.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"signature":"swift::TypeChecker::typeCheckTarget(swift::constraints::SyntacticElementTarget&, swift::optionset::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::DiagnosticTransaction*)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
enum a
44
protocol b {
55
associatedtype c

validation-test/compiler_crashers_2/c8563a4a60b27cf3.swift renamed to validation-test/compiler_crashers_2_fixed/c8563a4a60b27cf3.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"signature":"swift::CanTypeVisitor<swift::TypeMatcher<desugarSameTypeRequirement(swift::Requirement, swift::SourceLoc, llvm::SmallVectorImpl<swift::Requirement>&, llvm::SmallVectorImpl<swift::InverseRequirement>&, llvm::SmallVectorImpl<swift::rewriting::RequirementError>&)::Matcher>::MatchVisitor, bool, swift::Type, swift::Type>::visit(swift::CanType, swift::Type, swift::Type)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
protocol a {
44
associatedtype b associatedtype c associatedtype d func e(b, c) -> d
55
}

0 commit comments

Comments
 (0)