Skip to content

Commit b4d3237

Browse files
committed
[CSDiagnostics] Adjust diagnostics to account that type holes in solution are UnresolvedType
1 parent d039107 commit b4d3237

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5057,7 +5057,7 @@ bool CollectionElementContextualFailure::diagnoseAsError() {
50575057
// holes present in the contextual type.
50585058
if (FailureDiagnostic::getContextualTypePurpose(getAnchor()) ==
50595059
ContextualTypePurpose::CTP_ForEachStmt &&
5060-
contextualType->hasHole()) {
5060+
contextualType->hasUnresolvedType()) {
50615061
diagnostic.emplace(emitDiagnostic(
50625062
(contextualType->is<TupleType>() && !eltType->is<TupleType>())
50635063
? diag::cannot_match_expr_tuple_pattern_with_nontuple_value
@@ -6315,7 +6315,7 @@ bool UnableToInferClosureParameterType::diagnoseAsError() {
63156315
if (parentExpr) {
63166316
// Missing or invalid member reference in call.
63176317
if (auto *AE = dyn_cast<ApplyExpr>(parentExpr)) {
6318-
if (getType(AE->getFn())->isHole())
6318+
if (getType(AE->getFn())->is<UnresolvedType>())
63196319
return false;
63206320
}
63216321

lib/Sema/CSDiagnostics.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,26 @@ class FailureDiagnostic {
9494
/// Resolve type variables present in the raw type, if any.
9595
Type resolveType(Type rawType, bool reconstituteSugar = false,
9696
bool wantRValue = true) const {
97-
if (!rawType->hasTypeVariable()) {
98-
if (reconstituteSugar)
99-
rawType = rawType->reconstituteSugar(/*recursive*/ true);
100-
return wantRValue ? rawType->getRValueType() : rawType;
97+
auto &cs = getConstraintSystem();
98+
99+
if (rawType->hasTypeVariable() || rawType->hasHole()) {
100+
rawType = rawType.transform([&](Type type) {
101+
if (auto *typeVar = type->getAs<TypeVariableType>()) {
102+
auto resolvedType = S.simplifyType(typeVar);
103+
Type GP = typeVar->getImpl().getGenericParameter();
104+
return resolvedType->is<UnresolvedType>() && GP
105+
? GP
106+
: resolvedType;
107+
}
108+
109+
return type->isHole() ? Type(cs.getASTContext().TheUnresolvedType)
110+
: type;
111+
});
101112
}
102113

103-
auto &cs = getConstraintSystem();
104-
return cs.simplifyTypeImpl(rawType, [&](TypeVariableType *typeVar) -> Type {
105-
auto fixed = S.simplifyType(typeVar);
106-
auto *genericParam = typeVar->getImpl().getGenericParameter();
107-
if (fixed->isHole() && genericParam)
108-
return genericParam;
109-
return resolveType(fixed, reconstituteSugar, wantRValue);
110-
});
114+
if (reconstituteSugar)
115+
rawType = rawType->reconstituteSugar(/*recursive*/ true);
116+
return wantRValue ? rawType->getRValueType() : rawType;
111117
}
112118

113119
template <typename... ArgTypes>

test/Constraints/rdar44770297.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ protocol P {
44
associatedtype A
55
}
66

7-
func foo<T: P>(_: () throws -> T) -> T.A? {
7+
func foo<T: P>(_: () throws -> T) -> T.A? { // expected-note {{where 'T' = 'Never'}}
88
fatalError()
99
}
1010

11-
let _ = foo() {fatalError()} & nil // expected-error {{value of optional type 'Never.A?' must be unwrapped to a value of type 'Never.A'}}
12-
// expected-note@-1 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
13-
// expected-note@-2 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
11+
let _ = foo() {fatalError()} & nil // expected-error {{global function 'foo' requires that 'Never' conform to 'P'}}

0 commit comments

Comments
 (0)