Skip to content

[4.0] Sema: Ensure the array type for variadic tuple shuffles is always set. #10428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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 @@ -2858,9 +2858,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 @@ -2876,8 +2878,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 @@ -4877,20 +4877,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 @@ -4975,13 +4972,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 @@ -5609,16 +5606,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

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

_ = Butt()[1]