mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Sema] Handle PlaceholderTypes in associated type inference
Avoid attempting to infer an associatedtype as a type that contains placeholders.
This commit is contained in:
@@ -117,6 +117,12 @@ private:
|
||||
#define SINGLETON_TYPE(SHORT_ID, ID) TRIVIAL_CASE(ID##Type)
|
||||
#include "swift/AST/TypeNodes.def"
|
||||
|
||||
bool visitPlaceholderType(CanPlaceholderType firstType, Type secondType,
|
||||
Type sugaredFirstType) {
|
||||
// Placeholder types never match.
|
||||
return mismatch(firstType.getPointer(), secondType, sugaredFirstType);
|
||||
}
|
||||
|
||||
bool visitUnresolvedType(CanUnresolvedType firstType, Type secondType,
|
||||
Type sugaredFirstType) {
|
||||
// Unresolved types never match.
|
||||
|
||||
@@ -2317,9 +2317,9 @@ AssociatedTypeInference::getPotentialTypeWitnessesByMatchingTypes(ValueDecl *req
|
||||
/// Deduce associated types from dependent member types in the witness.
|
||||
bool mismatch(DependentMemberType *firstDepMember,
|
||||
TypeBase *secondType, Type sugaredFirstType) {
|
||||
// If the second type is an error, don't look at it further, but proceed
|
||||
// to find other matches.
|
||||
if (secondType->hasError())
|
||||
// If the second type is an error or placeholder, don't look at it
|
||||
// further, but proceed to find other matches.
|
||||
if (secondType->hasError() || secondType->hasPlaceholder())
|
||||
return true;
|
||||
|
||||
// If the second type is a generic parameter of the witness, the match
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// {"signature":"swift::TypeChecker::typeCheckTarget(swift::constraints::SyntacticElementTarget&, swift::optionset::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::DiagnosticTransaction*)"}
|
||||
// RUN: not --crash %target-swift-frontend -typecheck %s
|
||||
// RUN: not %target-swift-frontend -typecheck %s
|
||||
enum a
|
||||
protocol b {
|
||||
associatedtype c
|
||||
@@ -1,5 +1,5 @@
|
||||
// {"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)"}
|
||||
// RUN: not --crash %target-swift-frontend -typecheck %s
|
||||
// RUN: not %target-swift-frontend -typecheck %s
|
||||
protocol a {
|
||||
associatedtype b associatedtype c associatedtype d func e(b, c) -> d
|
||||
}
|
||||
Reference in New Issue
Block a user