mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
These were overlooked, and somehow code that attempted to make a minimal collection conform to RangeReplaceableCollection and RandomAccessCollection managed to compile successfully in Swift 3.0, but in Swift 3.1…*something* changed to reject a type that conforms to both due to the lack of a suitable default slicing subscript implementation in the stdlib that provided all the requirements. Fill in these missing implementations, fixing rdar://problem/30228957.
52 lines
1.3 KiB
Plaintext
52 lines
1.3 KiB
Plaintext
// RUN: rm -rf %t
|
|
// RUN: mkdir -p %t
|
|
// RUN: %gyb %s > %t/collection-combinatorics.swift
|
|
// RUN: %target-swift-frontend -typecheck -verify %t/collection-combinatorics.swift
|
|
|
|
// It should be possible to conform to any combination of
|
|
// (1 + RangeReplaceable) * (1 + Bidirectional + RandomAccess) * (1 + Mutable)
|
|
// Collection and get reasonable default implementations for slicing
|
|
// operations from
|
|
// the standard library.
|
|
|
|
% for mutable in ['', 'Mutable']:
|
|
% for rangeReplaceable in ['', 'RangeReplaceable']:
|
|
% for capability in ['', 'Bidirectional', 'RandomAccess']:
|
|
|
|
struct ${mutable}${rangeReplaceable}${capability}Butt
|
|
: ${mutable}Collection
|
|
% if rangeReplaceable:
|
|
, ${rangeReplaceable}Collection
|
|
% end
|
|
% if capability:
|
|
, ${capability}Collection
|
|
% end
|
|
{
|
|
subscript(i: Int) -> Int {
|
|
get { return 0 }
|
|
% if mutable:
|
|
set { }
|
|
% end
|
|
}
|
|
|
|
% if capability:
|
|
func index(before i: Int) -> Int {
|
|
return i - 1
|
|
}
|
|
% end
|
|
func index(after i: Int) -> Int {
|
|
return i + 1
|
|
}
|
|
|
|
var startIndex: Int { return .min }
|
|
var endIndex: Int { return .max }
|
|
|
|
% if rangeReplaceable:
|
|
init() {}
|
|
|
|
mutating func replaceSubrange<C: Collection>(_: Range<Int>, with: C)
|
|
where C.Iterator.Element == Int
|
|
{}
|
|
% end
|
|
}
|