Skip to content

Commit a46c484

Browse files
authored
Merge pull request #9748 from moiseev/rrc-filter-tests
[stdlib] More tests for RangeReplaceable.filter and Arrays
2 parents fe76f6b + 32027c8 commit a46c484

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

test/stdlib/ArrayFilter.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend -swift-version 4 -O %s -emit-sil | %FileCheck %s
2+
3+
// This test is testing that even in presence of
4+
// RangeReplaceableCollection.filter(_:), Arrays are still calling the default
5+
// implementation from Sequence.
6+
7+
// CHECK-NOT: RangeReplaceableCollection.filter(_:)
8+
@inline(never)
9+
public func foobar(_ xs: [Int]) -> [Int] {
10+
return xs.filter { _ in false }
11+
}
12+

test/stdlib/RangeReplaceableFilterCompatibility.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@ tests.test("Array.filter return type") {
2020
expectType([Int].self, &filtered)
2121
}
2222

23+
tests.test("ContiguousArray.filter return type") {
24+
var filtered = ContiguousArray(0..<10).filter { $0 % 2 == 0 }
25+
expectType([Int].self, &filtered)
26+
}
27+
28+
tests.test("ArraySlice.filter return type") {
29+
var filtered = Array(0..<10)[0..<10].filter { $0 % 2 == 0 }
30+
expectType([Int].self, &filtered)
31+
}
32+
2333
tests.test("String.filter can return [Character]") {
2434
let filtered = "Hello, World".filter { "A" <= $0 && $0 <= "Z"} as [Character]
2535
expectEqualSequence("HW", filtered)
2636
}
2737

28-
2938
runAllTests()
39+

0 commit comments

Comments
 (0)