Skip to content

Commit ee39236

Browse files
authored
Merge pull request #21295 from aschwaighofer/silgen_soften_assertion_in_project_open_opaque_existential_5.0
[5.0] SILGen: Soften assertions it is okay for an base value of an bo…
2 parents 3a9b12d + 53f74ac commit ee39236

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,8 +843,11 @@ namespace {
843843
ManagedValue base) && override {
844844
assert(base.getType().isExistentialType() &&
845845
"base for open existential component must be an existential");
846-
assert(base.getType().isAddress() &&
847-
"base value of open-existential component was not an address?");
846+
assert((base.getType().isAddress() ||
847+
base.getType().getPreferredExistentialRepresentation(SGF.SGM.M) ==
848+
ExistentialRepresentation::Boxed) &&
849+
"base value of open-existential component was not an address or a "
850+
"boxed existential?");
848851
SILValue addr;
849852

850853
auto rep = base.getType().getPreferredExistentialRepresentation(SGF.SGM.M);

test/SILGen/boxed_existentials.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,21 @@ func erasure_to_any(_ guaranteed: Error, _ immediate: Error) -> Any {
223223
return plusOneError()
224224
}
225225
}
226+
227+
extension Error {
228+
var myError: Error {
229+
return self
230+
}
231+
}
232+
233+
// Make sure we don't assert on this.
234+
// CHECK-LABEL: sil hidden @$s18boxed_existentials4testyyF
235+
// CHECK: [[ERROR_ADDR:%.*]] = alloc_stack $Error
236+
// CHECK: [[ARRAY_GET:%.*]] = function_ref @$sSayxSicig
237+
// CHECK: apply [[ARRAY_GET]]<Error>([[ERROR_ADDR]]
238+
// CHECK: [[ERROR:%.*]] = load [take] [[ERROR_ADDR]] : $*Error
239+
// CHECK: open_existential_box [[ERROR]]
240+
func test() {
241+
var errors: [Error] = []
242+
test_property(errors[0].myError)
243+
}

0 commit comments

Comments
 (0)