Skip to content

Commit 3f91c30

Browse files
authored
Merge pull request #4352 from rjmccall/collection-upcast-oves-3.0
Fix the open-existential remover to not die on the OVEs in collection upcasts
2 parents 38a0bbc + c5470ab commit 3f91c30

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3136,6 +3136,17 @@ static void eraseOpenedExistentials(Expr *&expr) {
31363136
"didn't see this OVE in a containing OpenExistentialExpr?");
31373137
return { true, value->second };
31383138
}
3139+
3140+
// Handle collection upcasts specially so that we don't blow up on
3141+
// their embedded OVEs.
3142+
if (auto CDE = dyn_cast<CollectionUpcastConversionExpr>(expr)) {
3143+
if (auto result = CDE->getSubExpr()->walk(*this)) {
3144+
CDE->setSubExpr(result);
3145+
return { false, CDE };
3146+
} else {
3147+
return { true, CDE };
3148+
}
3149+
}
31393150

31403151
return { true, expr };
31413152
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: not %target-swift-frontend %s -parse
2+
3+
class C {}
4+
class D : C {}
5+
6+
@_silgen_name("consume")
7+
func consume(_: [C]) // note, returns ()
8+
9+
// Assert/crash while emitting diagnostic for coercion from () to Bool
10+
// in the context of a collection cast.
11+
func test(x: [D]) -> Bool {
12+
return consume(x) // no way to coerce from () to Bool
13+
}

0 commit comments

Comments
 (0)