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
103 lines
2.5 KiB
Swift
103 lines
2.5 KiB
Swift
// RUN: %target-parse-verify-swift
|
|
|
|
protocol P {
|
|
typealias SomeType
|
|
}
|
|
|
|
protocol P2 {
|
|
func wonka()
|
|
}
|
|
|
|
extension Int : P {
|
|
typealias SomeType = Int
|
|
}
|
|
|
|
extension Double : P {
|
|
typealias SomeType = Double
|
|
}
|
|
|
|
func f0(x: Int,
|
|
_ y: Float) { }
|
|
|
|
func f1(_: (Int, Float) -> Int) { }
|
|
|
|
func f2(_: (_: (Int) -> Int)) -> Int {}
|
|
|
|
func f3(_: (_: (Int) -> Float) -> Int) {}
|
|
|
|
func f4(x: Int) -> Int { }
|
|
|
|
func f5<T : P2>(_ : T) { }
|
|
|
|
func f10<T : P, U : P where T.SomeType == U.SomeType>(t: T, _ u: U) {}
|
|
|
|
var i : Int
|
|
var d : Double
|
|
|
|
// Check the various forms of diagnostics the type checker can emit.
|
|
|
|
// Tuple size mismatch.
|
|
f1( // expected-error {{cannot invoke 'f1' with an argument list of type '((Int) -> Int)'}}
|
|
f4 // expected-note {{expected an argument list of type '((Int, Float) -> Int)'}}
|
|
)
|
|
|
|
// Tuple element unused.
|
|
f0(i, i, // expected-error{{extra argument in call}}
|
|
i)
|
|
|
|
// FIXME: Tuple name mismatch.
|
|
|
|
// FIXME: Position mismatch
|
|
// f5(f4)
|
|
|
|
// Tuple element not convertible.
|
|
f0(i, // expected-error {{cannot invoke 'f0' with an argument list of type '(Int, Double)'}} expected-note{{expected an argument list of type '(Int, Float)'}}
|
|
d
|
|
)
|
|
|
|
// Function result not a subtype.
|
|
f1( // expected-error {{cannot invoke 'f1' with an argument list of type '((Int, Float) -> ())'}}
|
|
f0 // expected-note{{expected an argument list of type '((Int, Float) -> Int)'}}
|
|
)
|
|
|
|
f3( // expected-error {{cannot invoke 'f3' with an argument list of type '((((Int) -> Int)) -> Int)'}}
|
|
f2 // expected-note{{expected an argument list of type '(((Int) -> Float) -> Int)'}}
|
|
)
|
|
|
|
// FIXME: Can't test same-type diagnostic yet.
|
|
// f4(i, d)
|
|
|
|
// FIXME: Can't test constructible requirement yet.
|
|
|
|
// Missing member.
|
|
i.wobble() // expected-error{{Int' does not have a member named 'wobble'}}
|
|
|
|
// Does not conform to protocol.
|
|
// FIXME: f5(i)
|
|
|
|
infix operator **** {
|
|
associativity left
|
|
precedence 200
|
|
}
|
|
|
|
func ****(_: Int, _: String) { }
|
|
i **** i // expected-error{{binary operator '****' cannot be applied to two Int operands}}
|
|
|
|
infix operator ***~ {
|
|
associativity left
|
|
precedence 200
|
|
}
|
|
|
|
func ***~(Int, String) { }
|
|
i ***~ i // expected-error{{binary operator '***~' cannot be applied to two Int operands}}
|
|
|
|
// <rdar://problem/20142523>
|
|
// FIXME: poor diagnostic, to be fixed in 20142462. For now, we just want to
|
|
// make sure that it doesn't crash.
|
|
func rdar20142523() {
|
|
map(0..<10, { x in // expected-error{{cannot find an overload for 'map' that accepts an argument list of type '(Range<Int>, (_) -> _)'}}
|
|
()
|
|
return x
|
|
})
|
|
}
|