Skip to content

Fix the open-existential remover to not die on the OVEs in collection upcasts #4352

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
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
11 changes: 11 additions & 0 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3136,6 +3136,17 @@ static void eraseOpenedExistentials(Expr *&expr) {
"didn't see this OVE in a containing OpenExistentialExpr?");
return { true, value->second };
}

// Handle collection upcasts specially so that we don't blow up on
// their embedded OVEs.
if (auto CDE = dyn_cast<CollectionUpcastConversionExpr>(expr)) {
if (auto result = CDE->getSubExpr()->walk(*this)) {
CDE->setSubExpr(result);
return { false, CDE };
} else {
return { true, CDE };
}
}

return { true, expr };
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: not %target-swift-frontend %s -parse

class C {}
class D : C {}

@_silgen_name("consume")
func consume(_: [C]) // note, returns ()

// Assert/crash while emitting diagnostic for coercion from () to Bool
// in the context of a collection cast.
func test(x: [D]) -> Bool {
return consume(x) // no way to coerce from () to Bool
}