Skip to content

Commit 556c744

Browse files
committed
[Diagnostics] Ignore result type failures if one side is a hole
If one of the sides in a application result conversion is a hole it could only mean that the fix has been recorded earlier (at the point where hole was introduced) and failure at function result position could be safely ignored. Resolves: rdar://79757320
1 parent aea8d24 commit 556c744

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4621,6 +4621,12 @@ bool ConstraintSystem::repairFailures(
46214621
}
46224622

46234623
case ConstraintLocator::FunctionResult: {
4624+
if (lhs->isPlaceholder() || rhs->isPlaceholder()) {
4625+
recordAnyTypeVarAsPotentialHole(lhs);
4626+
recordAnyTypeVarAsPotentialHole(rhs);
4627+
return true;
4628+
}
4629+
46244630
auto *loc = getConstraintLocator(anchor, {path.begin(), path.end() - 1});
46254631
// If this is a mismatch between contextual type and (trailing)
46264632
// closure with explicitly specified result type let's record it
@@ -4641,6 +4647,7 @@ bool ConstraintSystem::repairFailures(
46414647
break;
46424648
}
46434649
}
4650+
46444651
// Handle function result coerce expression wrong type conversion.
46454652
if (isExpr<CoerceExpr>(anchor)) {
46464653
auto *fix =

test/Constraints/generics.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,3 +905,28 @@ func rdar78781552() {
905905
// expected-error@-4 {{missing argument for parameter 'filter' in call}}
906906
}
907907
}
908+
909+
// rdar://79757320 - failured to produce a diagnostic when unresolved dependent member is used in function result position
910+
911+
protocol R_79757320 {
912+
associatedtype In
913+
associatedtype Out
914+
}
915+
916+
func rdar79757320() {
917+
struct Value<W> {
918+
init(_: W) {}
919+
920+
func formatted() -> String { "" }
921+
func formatted<T : R_79757320>(_: T) -> T.Out where T.In == Value<W> { fatalError() }
922+
}
923+
924+
struct Container {
925+
var value: String
926+
}
927+
928+
// FIXME: There has to be a way to propagate holes that makes it easy to suppress failures caused by missing members.
929+
_ = Container(value: Value(42).formatted(.S(a: .a, b: .b(0)))) // expected-error {{type 'R_79757320' has no member 'S'}}
930+
// expected-error@-1 {{cannot infer contextual base in reference to member 'a'}}
931+
// expected-error@-2 {{cannot infer contextual base in reference to member 'b'}}
932+
}

0 commit comments

Comments
 (0)