Skip to content

Commit 5fce236

Browse files
committed
[Sema] Fix a crash in rethrows checking.
We were assuming that variadic parameters are at the end, so we didn't fill in all the types of the tuple elements in the tuple type we were constructing.
1 parent 9152e29 commit 5fce236

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/Sema/TypeCheckError.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -770,7 +770,7 @@ class ApplyClassifier {
770770

771771
auto mapping = shuffle->getElementMapping();
772772
for (unsigned destIndex = 0; destIndex != mapping.size(); ++destIndex) {
773-
auto srcIndex = shuffle->getElementMapping()[destIndex];
773+
auto srcIndex = mapping[destIndex];
774774
if (srcIndex >= 0) {
775775
origSrcElts[srcIndex] = origParamTupleType->getElement(destIndex);
776776
} else if (srcIndex == TupleShuffleExpr::DefaultInitialize ||
@@ -785,9 +785,6 @@ class ApplyClassifier {
785785
origSrcElts[srcIndex] =
786786
origParamTupleType->getASTContext().TheRawPointerType;
787787
}
788-
789-
// We're done iterating these elements.
790-
break;
791788
} else {
792789
llvm_unreachable("bad source-element mapping!");
793790
}

test/decl/func/rethrows.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,9 @@ func rethrowsWithCaptureList<R, T>(
545545
return try operation(array.count)
546546
}
547547
}
548+
549+
// rdar://problem/40472018: Crash on rethrows function with variadic parameter and throwing function parameter.
550+
public func variadic_rethrows(_ values: Int..., body: (Int) throws -> ()) rethrows { }
551+
public func rdar40472018() {
552+
variadic_rethrows(1, 2) { _ in }
553+
}

0 commit comments

Comments
 (0)