Skip to content

Commit 6257ebe

Browse files
authored
Merge pull request #17203 from jckarter/rvalue-array-elements
Sema: Force the 'getElements' array of a type-checked ArrayExpr to contain rvalues.
2 parents e5ffbbe + 194f1f8 commit 6257ebe

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-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+
// 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)