Skip to content

Commit 001884e

Browse files
authored
Merge pull request #38235 from xedin/rdar-79757320
[Diagnostics] Ignore result type failures if one side is a hole
2 parents 139e8d2 + 556c744 commit 001884e

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4286,8 +4286,7 @@ bool ConstraintSystem::repairFailures(
42864286
// it's going to be diagnosed by specialized fix which deals
42874287
// with generic argument mismatches.
42884288
if (matchKind == ConstraintKind::BindToPointerType) {
4289-
auto *member = rhs->getAs<DependentMemberType>();
4290-
if (!(member && member->getBase()->hasPlaceholder()))
4289+
if (!rhs->isPlaceholder())
42914290
break;
42924291
}
42934292

@@ -4634,6 +4633,12 @@ bool ConstraintSystem::repairFailures(
46344633
}
46354634

46364635
case ConstraintLocator::FunctionResult: {
4636+
if (lhs->isPlaceholder() || rhs->isPlaceholder()) {
4637+
recordAnyTypeVarAsPotentialHole(lhs);
4638+
recordAnyTypeVarAsPotentialHole(rhs);
4639+
return true;
4640+
}
4641+
46374642
auto *loc = getConstraintLocator(anchor, {path.begin(), path.end() - 1});
46384643
// If this is a mismatch between contextual type and (trailing)
46394644
// closure with explicitly specified result type let's record it
@@ -4654,6 +4659,7 @@ bool ConstraintSystem::repairFailures(
46544659
break;
46554660
}
46564661
}
4662+
46574663
// Handle function result coerce expression wrong type conversion.
46584664
if (isExpr<CoerceExpr>(anchor)) {
46594665
auto *fix =

lib/Sema/ConstraintSystem.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,6 +2958,10 @@ Type ConstraintSystem::simplifyTypeImpl(Type type,
29582958
// Simplify the base.
29592959
Type newBase = simplifyTypeImpl(depMemTy->getBase(), getFixedTypeFn);
29602960

2961+
if (newBase->isPlaceholder()) {
2962+
return PlaceholderType::get(getASTContext(), depMemTy);
2963+
}
2964+
29612965
// If nothing changed, we're done.
29622966
if (newBase.getPointer() == depMemTy->getBase().getPointer())
29632967
return type;

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)