Skip to content

[Diagnostics] Ignore result type failures if one side is a hole #38235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4274,8 +4274,7 @@ bool ConstraintSystem::repairFailures(
// it's going to be diagnosed by specialized fix which deals
// with generic argument mismatches.
if (matchKind == ConstraintKind::BindToPointerType) {
auto *member = rhs->getAs<DependentMemberType>();
if (!(member && member->getBase()->hasPlaceholder()))
if (!rhs->isPlaceholder())
break;
}

Expand Down Expand Up @@ -4622,6 +4621,12 @@ bool ConstraintSystem::repairFailures(
}

case ConstraintLocator::FunctionResult: {
if (lhs->isPlaceholder() || rhs->isPlaceholder()) {
recordAnyTypeVarAsPotentialHole(lhs);
recordAnyTypeVarAsPotentialHole(rhs);
return true;
}

auto *loc = getConstraintLocator(anchor, {path.begin(), path.end() - 1});
// If this is a mismatch between contextual type and (trailing)
// closure with explicitly specified result type let's record it
Expand All @@ -4642,6 +4647,7 @@ bool ConstraintSystem::repairFailures(
break;
}
}

// Handle function result coerce expression wrong type conversion.
if (isExpr<CoerceExpr>(anchor)) {
auto *fix =
Expand Down
4 changes: 4 additions & 0 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2958,6 +2958,10 @@ Type ConstraintSystem::simplifyTypeImpl(Type type,
// Simplify the base.
Type newBase = simplifyTypeImpl(depMemTy->getBase(), getFixedTypeFn);

if (newBase->isPlaceholder()) {
return PlaceholderType::get(getASTContext(), depMemTy);
}

// If nothing changed, we're done.
if (newBase.getPointer() == depMemTy->getBase().getPointer())
return type;
Expand Down
25 changes: 25 additions & 0 deletions test/Constraints/generics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -905,3 +905,28 @@ func rdar78781552() {
// expected-error@-4 {{missing argument for parameter 'filter' in call}}
}
}

// rdar://79757320 - failured to produce a diagnostic when unresolved dependent member is used in function result position

protocol R_79757320 {
associatedtype In
associatedtype Out
}

func rdar79757320() {
struct Value<W> {
init(_: W) {}

func formatted() -> String { "" }
func formatted<T : R_79757320>(_: T) -> T.Out where T.In == Value<W> { fatalError() }
}

struct Container {
var value: String
}

// FIXME: There has to be a way to propagate holes that makes it easy to suppress failures caused by missing members.
_ = Container(value: Value(42).formatted(.S(a: .a, b: .b(0)))) // expected-error {{type 'R_79757320' has no member 'S'}}
// expected-error@-1 {{cannot infer contextual base in reference to member 'a'}}
// expected-error@-2 {{cannot infer contextual base in reference to member 'b'}}
}