Skip to content

Commit 4048c96

Browse files
authored
Merge pull request #10428 from jckarter/tuple-shuffle-vararg-type-4.0
[4.0] Sema: Ensure the array type for variadic tuple shuffles is always set.
2 parents 3f0f5df + e19cefa commit 4048c96

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

include/swift/AST/Expr.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,9 +2858,11 @@ class TupleShuffleExpr : public ImplicitConversionExpr {
28582858
SourceIsScalar_t isSourceScalar,
28592859
ConcreteDeclRef defaultArgsOwner,
28602860
ArrayRef<unsigned> VariadicArgs,
2861-
MutableArrayRef<Expr *> CallerDefaultArgs, Type ty)
2861+
Type VarargsArrayTy,
2862+
MutableArrayRef<Expr *> CallerDefaultArgs,
2863+
Type ty)
28622864
: ImplicitConversionExpr(ExprKind::TupleShuffle, subExpr, ty),
2863-
ElementMapping(elementMapping), VarargsArrayTy(),
2865+
ElementMapping(elementMapping), VarargsArrayTy(VarargsArrayTy),
28642866
DefaultArgsOwner(defaultArgsOwner), VariadicArgs(VariadicArgs),
28652867
CallerDefaultArgs(CallerDefaultArgs)
28662868
{
@@ -2876,8 +2878,6 @@ class TupleShuffleExpr : public ImplicitConversionExpr {
28762878
/// single-element tuple for the purposes of interpreting behavior.
28772879
bool isSourceScalar() const { return TupleShuffleExprBits.IsSourceScalar; }
28782880

2879-
/// Set the varargs array type to use.
2880-
void setVarargsArrayType(Type T) { VarargsArrayTy = T; }
28812881
Type getVarargsArrayType() const {
28822882
assert(!VarargsArrayTy.isNull());
28832883
return VarargsArrayTy;

lib/Sema/CSApply.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4877,20 +4877,17 @@ Expr *ExprRewriter::coerceTupleToTuple(Expr *expr, TupleType *fromTuple,
48774877
// Create the tuple shuffle.
48784878
ArrayRef<int> mapping = tc.Context.AllocateCopy(sources);
48794879
auto callerDefaultArgsCopy = tc.Context.AllocateCopy(callerDefaultArgs);
4880-
auto shuffle =
4880+
return
48814881
cs.cacheType(new (tc.Context) TupleShuffleExpr(
48824882
expr, mapping,
48834883
TupleShuffleExpr::SourceIsTuple,
48844884
callee,
48854885
tc.Context.AllocateCopy(variadicArgs),
4886+
arrayType,
48864887
callerDefaultArgsCopy,
48874888
toSugarType));
4888-
shuffle->setVarargsArrayType(arrayType);
4889-
return shuffle;
48904889
}
48914890

4892-
4893-
48944891
Expr *ExprRewriter::coerceScalarToTuple(Expr *expr, TupleType *toTuple,
48954892
int toScalarIdx,
48964893
ConstraintLocatorBuilder locator) {
@@ -4975,13 +4972,13 @@ Expr *ExprRewriter::coerceScalarToTuple(Expr *expr, TupleType *toTuple,
49754972

49764973
Type destSugarTy = hasInit? toTuple
49774974
: TupleType::get(sugarFields, tc.Context);
4978-
4979-
return cs.cacheType(
4980-
new (tc.Context) TupleShuffleExpr(expr,
4975+
4976+
return cs.cacheType(new (tc.Context) TupleShuffleExpr(expr,
49814977
tc.Context.AllocateCopy(elements),
49824978
TupleShuffleExpr::SourceIsScalar,
49834979
callee,
49844980
tc.Context.AllocateCopy(variadicArgs),
4981+
arrayType,
49854982
tc.Context.AllocateCopy(callerDefaultArgs),
49864983
destSugarTy));
49874984
}
@@ -5609,16 +5606,15 @@ Expr *ExprRewriter::coerceCallArguments(
56095606
// Create the tuple shuffle.
56105607
ArrayRef<int> mapping = tc.Context.AllocateCopy(sources);
56115608
auto callerDefaultArgsCopy = tc.Context.AllocateCopy(callerDefaultArgs);
5612-
auto *shuffle =
5609+
return
56135610
cs.cacheType(new (tc.Context) TupleShuffleExpr(
56145611
arg, mapping,
56155612
isSourceScalar,
56165613
callee,
56175614
tc.Context.AllocateCopy(variadicArgs),
5615+
sliceType,
56185616
callerDefaultArgsCopy,
56195617
paramType));
5620-
shuffle->setVarargsArrayType(sliceType);
5621-
return shuffle;
56225618
}
56235619

56245620
static ClosureExpr *getClosureLiteralExpr(Expr *expr) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-frontend -emit-silgen -verify %s
2+
3+
struct Butt {
4+
subscript(butts: Int...) -> Int {
5+
return 0
6+
}
7+
}
8+
9+
_ = Butt()[1]

0 commit comments

Comments
 (0)