Skip to content

Commit fc18cb8

Browse files
authored
Merge pull request swiftlang#10427 from jckarter/tuple-shuffle-vararg-type
Sema: Ensure the array type for variadic tuple shuffles is always set.
2 parents b5f28bf + 8548693 commit fc18cb8

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
@@ -2854,9 +2854,11 @@ class TupleShuffleExpr : public ImplicitConversionExpr {
28542854
SourceIsScalar_t isSourceScalar,
28552855
ConcreteDeclRef defaultArgsOwner,
28562856
ArrayRef<unsigned> VariadicArgs,
2857-
MutableArrayRef<Expr *> CallerDefaultArgs, Type ty)
2857+
Type VarargsArrayTy,
2858+
MutableArrayRef<Expr *> CallerDefaultArgs,
2859+
Type ty)
28582860
: ImplicitConversionExpr(ExprKind::TupleShuffle, subExpr, ty),
2859-
ElementMapping(elementMapping), VarargsArrayTy(),
2861+
ElementMapping(elementMapping), VarargsArrayTy(VarargsArrayTy),
28602862
DefaultArgsOwner(defaultArgsOwner), VariadicArgs(VariadicArgs),
28612863
CallerDefaultArgs(CallerDefaultArgs)
28622864
{
@@ -2872,8 +2874,6 @@ class TupleShuffleExpr : public ImplicitConversionExpr {
28722874
/// single-element tuple for the purposes of interpreting behavior.
28732875
bool isSourceScalar() const { return TupleShuffleExprBits.IsSourceScalar; }
28742876

2875-
/// Set the varargs array type to use.
2876-
void setVarargsArrayType(Type T) { VarargsArrayTy = T; }
28772877
Type getVarargsArrayType() const {
28782878
assert(!VarargsArrayTy.isNull());
28792879
return VarargsArrayTy;

lib/Sema/CSApply.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4746,20 +4746,17 @@ Expr *ExprRewriter::coerceTupleToTuple(Expr *expr, TupleType *fromTuple,
47464746
// Create the tuple shuffle.
47474747
ArrayRef<int> mapping = tc.Context.AllocateCopy(sources);
47484748
auto callerDefaultArgsCopy = tc.Context.AllocateCopy(callerDefaultArgs);
4749-
auto shuffle =
4749+
return
47504750
cs.cacheType(new (tc.Context) TupleShuffleExpr(
47514751
expr, mapping,
47524752
TupleShuffleExpr::SourceIsTuple,
47534753
callee,
47544754
tc.Context.AllocateCopy(variadicArgs),
4755+
arrayType,
47554756
callerDefaultArgsCopy,
47564757
toSugarType));
4757-
shuffle->setVarargsArrayType(arrayType);
4758-
return shuffle;
47594758
}
47604759

4761-
4762-
47634760
Expr *ExprRewriter::coerceScalarToTuple(Expr *expr, TupleType *toTuple,
47644761
int toScalarIdx,
47654762
ConstraintLocatorBuilder locator) {
@@ -4844,13 +4841,13 @@ Expr *ExprRewriter::coerceScalarToTuple(Expr *expr, TupleType *toTuple,
48444841

48454842
Type destSugarTy = hasInit? toTuple
48464843
: TupleType::get(sugarFields, tc.Context);
4847-
4848-
return cs.cacheType(
4849-
new (tc.Context) TupleShuffleExpr(expr,
4844+
4845+
return cs.cacheType(new (tc.Context) TupleShuffleExpr(expr,
48504846
tc.Context.AllocateCopy(elements),
48514847
TupleShuffleExpr::SourceIsScalar,
48524848
callee,
48534849
tc.Context.AllocateCopy(variadicArgs),
4850+
arrayType,
48544851
tc.Context.AllocateCopy(callerDefaultArgs),
48554852
destSugarTy));
48564853
}
@@ -5473,16 +5470,15 @@ Expr *ExprRewriter::coerceCallArguments(
54735470
// Create the tuple shuffle.
54745471
ArrayRef<int> mapping = tc.Context.AllocateCopy(sources);
54755472
auto callerDefaultArgsCopy = tc.Context.AllocateCopy(callerDefaultArgs);
5476-
auto *shuffle =
5473+
return
54775474
cs.cacheType(new (tc.Context) TupleShuffleExpr(
54785475
arg, mapping,
54795476
isSourceScalar,
54805477
callee,
54815478
tc.Context.AllocateCopy(variadicArgs),
5479+
sliceType,
54825480
callerDefaultArgsCopy,
54835481
paramType));
5484-
shuffle->setVarargsArrayType(sliceType);
5485-
return shuffle;
54865482
}
54875483

54885484
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)