Files
swift-mirror/test/decl/func/vararg.swift
Doug Gregor 793b3326af Implement the new rules for argument label defaults.
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
2015-04-24 19:03:30 +00:00

24 lines
598 B
Swift

// RUN: %target-parse-verify-swift
var t1a: (Int...) = (1) // expected-error{{cannot create a variadic tuple}}
var t2d: (Double = 0.0) = 1 // expected-error {{default argument not permitted in a tuple type}}
func f1(a: Int...) { for x in a {} }
f1()
f1(1)
f1(1,2)
func f2(a: Int, _ b: Int...) { for x in b {} }
f2(1)
f2(1,2)
f2(1,2,3)
func f3(a: (String) -> Void) { }
f3({ print($0) })
func f4(a: Int..., b: Int) { } // expected-error{{'...' must be on the last parameter}}
// rdar://16008564
func inout_variadic(inout i: Int...) { // expected-error {{inout arguments cannot be variadic}}
}