Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2854,9 +2854,11 @@ class TupleShuffleExpr : public ImplicitConversionExpr {
SourceIsScalar_t isSourceScalar,
ConcreteDeclRef defaultArgsOwner,
ArrayRef<unsigned> VariadicArgs,
MutableArrayRef<Expr *> CallerDefaultArgs, Type ty)
Type VarargsArrayTy,
MutableArrayRef<Expr *> CallerDefaultArgs,
Type ty)
: ImplicitConversionExpr(ExprKind::TupleShuffle, subExpr, ty),
ElementMapping(elementMapping), VarargsArrayTy(),
ElementMapping(elementMapping), VarargsArrayTy(VarargsArrayTy),
DefaultArgsOwner(defaultArgsOwner), VariadicArgs(VariadicArgs),
CallerDefaultArgs(CallerDefaultArgs)
{
Expand All @@ -2872,8 +2874,6 @@ class TupleShuffleExpr : public ImplicitConversionExpr {
/// single-element tuple for the purposes of interpreting behavior.
bool isSourceScalar() const { return TupleShuffleExprBits.IsSourceScalar; }

/// Set the varargs array type to use.
void setVarargsArrayType(Type T) { VarargsArrayTy = T; }
Type getVarargsArrayType() const {
assert(!VarargsArrayTy.isNull());
return VarargsArrayTy;
Expand Down
18 changes: 7 additions & 11 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4746,20 +4746,17 @@ Expr *ExprRewriter::coerceTupleToTuple(Expr *expr, TupleType *fromTuple,
// Create the tuple shuffle.
ArrayRef<int> mapping = tc.Context.AllocateCopy(sources);
auto callerDefaultArgsCopy = tc.Context.AllocateCopy(callerDefaultArgs);
auto shuffle =
return
cs.cacheType(new (tc.Context) TupleShuffleExpr(
expr, mapping,
TupleShuffleExpr::SourceIsTuple,
callee,
tc.Context.AllocateCopy(variadicArgs),
arrayType,
callerDefaultArgsCopy,
toSugarType));
shuffle->setVarargsArrayType(arrayType);
return shuffle;
}



Expr *ExprRewriter::coerceScalarToTuple(Expr *expr, TupleType *toTuple,
int toScalarIdx,
ConstraintLocatorBuilder locator) {
Expand Down Expand Up @@ -4844,13 +4841,13 @@ Expr *ExprRewriter::coerceScalarToTuple(Expr *expr, TupleType *toTuple,

Type destSugarTy = hasInit? toTuple
: TupleType::get(sugarFields, tc.Context);

return cs.cacheType(
new (tc.Context) TupleShuffleExpr(expr,

return cs.cacheType(new (tc.Context) TupleShuffleExpr(expr,
tc.Context.AllocateCopy(elements),
TupleShuffleExpr::SourceIsScalar,
callee,
tc.Context.AllocateCopy(variadicArgs),
arrayType,
tc.Context.AllocateCopy(callerDefaultArgs),
destSugarTy));
}
Expand Down Expand Up @@ -5473,16 +5470,15 @@ Expr *ExprRewriter::coerceCallArguments(
// Create the tuple shuffle.
ArrayRef<int> mapping = tc.Context.AllocateCopy(sources);
auto callerDefaultArgsCopy = tc.Context.AllocateCopy(callerDefaultArgs);
auto *shuffle =
return
cs.cacheType(new (tc.Context) TupleShuffleExpr(
arg, mapping,
isSourceScalar,
callee,
tc.Context.AllocateCopy(variadicArgs),
sliceType,
callerDefaultArgsCopy,
paramType));
shuffle->setVarargsArrayType(sliceType);
return shuffle;
}

static ClosureExpr *getClosureLiteralExpr(Expr *expr) {
Expand Down
9 changes: 9 additions & 0 deletions test/SILGen/variadic-subscript-single-arg.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %target-swift-frontend -emit-silgen -verify %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're not emitting diagnostics I don't think the -verify is necessary.


struct Butt {
subscript(butts: Int...) -> Int {
return 0
}
}

_ = Butt()[1]