Skip to content

Commit fde0d92

Browse files
Add conditional Lazy conformance to Slice when Base is Lazy (#13242)
1 parent dfa4b77 commit fde0d92

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

stdlib/public/core/LazyCollection.swift.gyb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ extension ${TraversalCollection} where Self : LazyCollectionProtocol {
266266

267267
% end
268268

269+
extension Slice: LazySequenceProtocol where Base: LazySequenceProtocol { }
270+
extension Slice: LazyCollectionProtocol where Base: LazyCollectionProtocol { }
271+
269272
// ${'Local Variables'}:
270273
// eval: (read-only-mode 1)
271274
// End:

test/stdlib/LazySlice.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: rm -rf %t ; mkdir -p %t
2+
// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
3+
// REQUIRES: executable_test
4+
5+
import StdlibUnittest
6+
7+
var tests = TestSuite("LazySlice")
8+
9+
tests.test("CommuteLazyness") {
10+
let a = [1,2,3].lazy
11+
let b = a[...]
12+
var c = b.filter { $0 == 0 }
13+
// NOTE, this test will fail once lazy collectionness becomes a conditiona
14+
// conformance, and will need updating to be a LazyBidirectional thingy
15+
expectType(LazyFilterBidirectionalCollection<Slice<LazyRandomAccessCollection<[Int]>>>.self, &c)
16+
}
17+
18+
runAllTests()

0 commit comments

Comments
 (0)