Skip to content

Commit 194f1f8

Browse files
committed
Sema: Force the 'getElements' array of a type-checked ArrayExpr to contain rvalues.
There are other parts of CSApply that attempt to peephole transform ArrayExprs (particularly bridging, which tries to turn `[x, y, ...] as T` into `[x as T, y as T, ...]`) and expect the elements to have already been rvalue-d. Fixes rdar://problem/40859007.
1 parent 3b03111 commit 194f1f8

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lib/Sema/CSApply.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,6 +2988,14 @@ namespace {
29882988
DeclName name(tc.Context, DeclBaseName::createConstructor(),
29892989
{ tc.Context.Id_arrayLiteral });
29902990

2991+
// Coerce the array elements to be rvalues, so that other type-checker
2992+
// code that attempts to peephole the AST doesn't have to re-load the
2993+
// elements (and break the invariant that lvalue nodes only get their
2994+
// access kind set once).
2995+
for (auto &element : expr->getElements()) {
2996+
element = cs.coerceToRValue(element);
2997+
}
2998+
29912999
// Restructure the argument to provide the appropriate labels in the
29923000
// tuple.
29933001
SmallVector<TupleTypeElt, 4> typeElements;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
struct B {
2+
var other: Int = 0
3+
lazy var crash: String = {
4+
return ""
5+
}()
6+
}
7+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-silgen -verify %s
2+
// REQUIRES: objc_interop
3+
import Foundation
4+
5+
var x = 1
6+
7+
_ = [x] as [NSNumber]

0 commit comments

Comments
 (0)