Skip to content

Commit 5a01af3

Browse files
authored
Merge pull request #13736 from moiseev/rrc-ops
[stdlib] Rearrange + on RangeReplaceableCollection/Sequence once again
2 parents 0782b48 + 9bf8d77 commit 5a01af3

File tree

2 files changed

+36
-39
lines changed

2 files changed

+36
-39
lines changed

stdlib/public/core/RangeReplaceableCollection.swift

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -903,36 +903,6 @@ extension RangeReplaceableCollection
903903
}
904904

905905
extension Sequence {
906-
/// Creates a new collection by concatenating the elements of a collection and
907-
/// a sequence.
908-
///
909-
/// The two arguments must have the same `Element` type. For example, you can
910-
/// concatenate the elements of an integer array and a `Range<Int>` instance.
911-
///
912-
/// let numbers = [1, 2, 3, 4]
913-
/// let moreNumbers = numbers + 5...10
914-
/// print(moreNumbers)
915-
/// // Prints "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
916-
///
917-
/// The resulting collection has the type of the argument on the left-hand
918-
/// side. In the example above, `moreNumbers` has the same type as `numbers`,
919-
/// which is `[Int]`.
920-
///
921-
/// - Parameters:
922-
/// - lhs: A range-replaceable collection.
923-
/// - rhs: A collection or finite sequence.
924-
@_inlineable
925-
public static func + <
926-
Other : RangeReplaceableCollection
927-
>(lhs: Other, rhs: Self) -> Other
928-
where Element == Other.Element {
929-
930-
var lhs = lhs
931-
// FIXME: what if lhs is a reference type? This will mutate it.
932-
lhs.append(contentsOf: rhs)
933-
return lhs
934-
}
935-
936906
/// Creates a new collection by concatenating the elements of a sequence and a
937907
/// collection.
938908
///
@@ -956,13 +926,43 @@ extension Sequence {
956926
Other : RangeReplaceableCollection
957927
>(lhs: Self, rhs: Other) -> Other
958928
where Element == Other.Element {
959-
960929
var result = Other()
961930
result.reserveCapacity(rhs.count + numericCast(lhs.underestimatedCount))
962931
result.append(contentsOf: lhs)
963932
result.append(contentsOf: rhs)
964933
return result
965934
}
935+
}
936+
937+
extension RangeReplaceableCollection {
938+
/// Creates a new collection by concatenating the elements of a collection and
939+
/// a sequence.
940+
///
941+
/// The two arguments must have the same `Element` type. For example, you can
942+
/// concatenate the elements of an integer array and a `Range<Int>` instance.
943+
///
944+
/// let numbers = [1, 2, 3, 4]
945+
/// let moreNumbers = numbers + 5...10
946+
/// print(moreNumbers)
947+
/// // Prints "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
948+
///
949+
/// The resulting collection has the type of the argument on the left-hand
950+
/// side. In the example above, `moreNumbers` has the same type as `numbers`,
951+
/// which is `[Int]`.
952+
///
953+
/// - Parameters:
954+
/// - lhs: A range-replaceable collection.
955+
/// - rhs: A collection or finite sequence.
956+
@_inlineable
957+
public static func + <
958+
Other : Sequence
959+
>(lhs: Self, rhs: Other) -> Self
960+
where Element == Other.Element {
961+
var lhs = lhs
962+
// FIXME: what if lhs is a reference type? This will mutate it.
963+
lhs.append(contentsOf: rhs)
964+
return lhs
965+
}
966966

967967
/// Appends the elements of a sequence to a range-replaceable collection.
968968
///
@@ -982,14 +982,12 @@ extension Sequence {
982982
/// - Complexity: O(*n*), where *n* is the length of the resulting array.
983983
@_inlineable
984984
public static func += <
985-
Other : RangeReplaceableCollection
986-
>(lhs: inout Other, rhs: Self)
985+
Other : Sequence
986+
>(lhs: inout Self, rhs: Other)
987987
where Element == Other.Element {
988988
lhs.append(contentsOf: rhs)
989989
}
990-
}
991990

992-
extension RangeReplaceableCollection {
993991
/// Creates a new collection by concatenating the elements of two collections.
994992
///
995993
/// The two arguments must have the same `Element` type. For example, you can
@@ -1009,11 +1007,10 @@ extension RangeReplaceableCollection {
10091007
/// - lhs: A range-replaceable collection.
10101008
/// - rhs: Another range-replaceable collection.
10111009
@_inlineable
1012-
public static func +<
1010+
public static func + <
10131011
Other : RangeReplaceableCollection
10141012
>(lhs: Self, rhs: Other) -> Self
1015-
where Element == Other.Element {
1016-
1013+
where Element == Other.Element {
10171014
var lhs = lhs
10181015
// FIXME: what if lhs is a reference type? This will mutate it.
10191016
lhs.append(contentsOf: rhs)

test/Constraints/bridging.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func rdar19831698() {
269269
var v72 = true + true // expected-error{{binary operator '+' cannot be applied to two 'Bool' operands}}
270270
// expected-note @-1 {{overloads for '+' exist with these partially matching parameter lists:}}
271271
var v73 = true + [] // expected-error{{binary operator '+' cannot be applied to operands of type 'Bool' and '[Any]'}}
272-
// expected-note @-1 {{overloads for '+' exist with these partially matching parameter lists:}}
272+
// expected-note @-1 {{expected an argument list of type '(Self, Other)'}}
273273
var v75 = true + "str" // expected-error {{binary operator '+' cannot be applied to operands of type 'Bool' and 'String'}} expected-note {{expected an argument list of type '(String, String)'}}
274274
}
275275

0 commit comments

Comments
 (0)