mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The rule changes are as follows: * All functions (introduced with the 'func' keyword) have argument labels for arguments beyond the first, by default. Methods are no longer special in this regard. * The presence of a default argument no longer implies an argument label. The actual changes to the parser and printer are fairly simple; the rest of the noise is updating the standard library, overlays, tests, etc. With the standard library, this change is intended to be API neutral: I've added/removed #'s and _'s as appropriate to keep the user interface the same. If we want to separately consider using argument labels for more free functions now that the defaults in the language have shifted, we can tackle that separately. Fixes rdar://problem/17218256. Swift SVN r27704
128 lines
2.2 KiB
Swift
128 lines
2.2 KiB
Swift
public struct Empty {}
|
|
|
|
public struct TwoInts {
|
|
public var x, y : Int
|
|
public init(x: Int, y: Int) {
|
|
self.x = x
|
|
self.y = y
|
|
}
|
|
}
|
|
|
|
public struct ComputedProperty {
|
|
public var value : Int {
|
|
get {
|
|
var result = 0
|
|
return result
|
|
}
|
|
}
|
|
}
|
|
|
|
// Generics
|
|
public struct Pair<A, B> {
|
|
public var first : A
|
|
public var second : B
|
|
|
|
public init(a : A, b : B) {
|
|
first = a
|
|
second = b
|
|
}
|
|
}
|
|
|
|
public typealias VoidPairTuple = ((), ())
|
|
|
|
public struct GenericCtor<U> {
|
|
public init<T>(_ t : T) {}
|
|
|
|
public func doSomething<T>(t: T) {}
|
|
}
|
|
|
|
// Protocols
|
|
public protocol Resettable {
|
|
mutating
|
|
func reset()
|
|
}
|
|
|
|
public struct ResettableIntWrapper : Resettable {
|
|
public var value : Int
|
|
public mutating
|
|
func reset() {
|
|
var zero = 0
|
|
value = zero
|
|
}
|
|
public init(value: Int) { self.value = value }
|
|
}
|
|
|
|
public protocol Computable {
|
|
mutating
|
|
func compute()
|
|
}
|
|
|
|
public typealias Cacheable = protocol<Resettable, Computable>
|
|
|
|
public protocol SpecialResettable : Resettable, Computable {}
|
|
|
|
public protocol HasAssociatedType {
|
|
typealias ComputableType : Computable
|
|
}
|
|
|
|
public struct ComputableWrapper<T : Computable> : HasAssociatedType {
|
|
public typealias ComputableType = T
|
|
public init() {}
|
|
}
|
|
|
|
public protocol AnotherAssociatedType {
|
|
typealias ResettableType : Resettable
|
|
}
|
|
|
|
public struct ResettableWrapper<T : Resettable> : AnotherAssociatedType {
|
|
public typealias ResettableType = T
|
|
public init() {}
|
|
}
|
|
|
|
public func cacheViaWrappers<
|
|
T : HasAssociatedType, U : AnotherAssociatedType
|
|
where T.ComputableType == U.ResettableType
|
|
>(computable : T, _ resettable : U) {}
|
|
|
|
|
|
// Subscripts
|
|
public struct ReadonlySimpleSubscript {
|
|
public subscript(x : Int) -> Bool {
|
|
return true
|
|
}
|
|
public init() {}
|
|
}
|
|
|
|
public struct ComplexSubscript {
|
|
public subscript(x : Int, y : Bool) -> Int {
|
|
set(newValue) {
|
|
// do nothing!
|
|
}
|
|
get {
|
|
return 0
|
|
}
|
|
}
|
|
public init() {}
|
|
}
|
|
|
|
|
|
// Extensions
|
|
public extension Empty {
|
|
public func doAbsolutelyNothing() {}
|
|
}
|
|
|
|
public struct UnComputable {}
|
|
extension UnComputable : Computable {
|
|
public init(x : Int) {}
|
|
public func compute() {}
|
|
public static func canCompute() -> Bool {
|
|
return true
|
|
}
|
|
}
|
|
|
|
public extension Pair {
|
|
public func swap() -> (B, A) {
|
|
return (second, first)
|
|
}
|
|
}
|