Skip to content

Commit 981613b

Browse files
authored
Merge pull request #17245 from jckarter/rvalue-array-elements-4.2
[4.2] Sema: Force the 'getElements' array of a type-checked ArrayExpr to contain rvalues.
2 parents b88269b + fad70f7 commit 981613b

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
@@ -3015,6 +3015,14 @@ namespace {
30153015
DeclName name(tc.Context, DeclBaseName::createConstructor(),
30163016
{ tc.Context.Id_arrayLiteral });
30173017

3018+
// Coerce the array elements to be rvalues, so that other type-checker
3019+
// code that attempts to peephole the AST doesn't have to re-load the
3020+
// elements (and break the invariant that lvalue nodes only get their
3021+
// access kind set once).
3022+
for (auto &element : expr->getElements()) {
3023+
element = cs.coerceToRValue(element);
3024+
}
3025+
30183026
// Restructure the argument to provide the appropriate labels in the
30193027
// tuple.
30203028
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)