Skip to content

Commit 499cefd

Browse files
authored
Merge pull request #38278 from xedin/rdar-79757320-5.5
[5.5][Diagnostics] Ignore result type failures if one side is a hole
2 parents 7973160 + 7c09943 commit 499cefd

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
@@ -4277,8 +4277,7 @@ bool ConstraintSystem::repairFailures(
42774277
// it's going to be diagnosed by specialized fix which deals
42784278
// with generic argument mismatches.
42794279
if (matchKind == ConstraintKind::BindToPointerType) {
4280-
auto *member = rhs->getAs<DependentMemberType>();
4281-
if (!(member && member->getBase()->hasPlaceholder()))
4280+
if (!rhs->isPlaceholder())
42824281
break;
42834282
}
42844283

@@ -4619,6 +4618,12 @@ bool ConstraintSystem::repairFailures(
46194618
}
46204619

46214620
case ConstraintLocator::FunctionResult: {
4621+
if (lhs->isPlaceholder() || rhs->isPlaceholder()) {
4622+
markAnyTypeVarsAsPotentialHoles(lhs);
4623+
markAnyTypeVarsAsPotentialHoles(rhs);
4624+
return true;
4625+
}
4626+
46224627
auto *loc = getConstraintLocator(anchor, {path.begin(), path.end() - 1});
46234628
// If this is a mismatch between contextual type and (trailing)
46244629
// closure with explicitly specified result type let's record it
@@ -4639,6 +4644,7 @@ bool ConstraintSystem::repairFailures(
46394644
break;
46404645
}
46414646
}
4647+
46424648
// Handle function result coerce expression wrong type conversion.
46434649
if (isExpr<CoerceExpr>(anchor)) {
46444650
auto *fix =

lib/Sema/ConstraintSystem.cpp

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

2970+
if (newBase->isPlaceholder()) {
2971+
return PlaceholderType::get(getASTContext(), depMemTy);
2972+
}
2973+
29702974
// If nothing changed, we're done.
29712975
if (newBase.getPointer() == depMemTy->getBase().getPointer())
29722976
return type;

test/Constraints/generics.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,3 +893,28 @@ func rdar78781552() {
893893
// expected-error@-4 {{missing argument for parameter 'filter' in call}}
894894
}
895895
}
896+
897+
// rdar://79757320 - failured to produce a diagnostic when unresolved dependent member is used in function result position
898+
899+
protocol R_79757320 {
900+
associatedtype In
901+
associatedtype Out
902+
}
903+
904+
func rdar79757320() {
905+
struct Value<W> {
906+
init(_: W) {}
907+
908+
func formatted() -> String { "" }
909+
func formatted<T : R_79757320>(_: T) -> T.Out where T.In == Value<W> { fatalError() }
910+
}
911+
912+
struct Container {
913+
var value: String
914+
}
915+
916+
// FIXME: There has to be a way to propagate holes that makes it easy to suppress failures caused by missing members.
917+
_ = Container(value: Value(42).formatted(.S(a: .a, b: .b(0)))) // expected-error {{type 'R_79757320' has no member 'S'}}
918+
// expected-error@-1 {{cannot infer contextual base in reference to member 'a'}}
919+
// expected-error@-2 {{cannot infer contextual base in reference to member 'b'}}
920+
}

0 commit comments

Comments
 (0)