mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +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
130 lines
3.5 KiB
Swift
130 lines
3.5 KiB
Swift
// RUN: %target-swift-frontend -dump-ast %s 2>&1 | FileCheck %s
|
|
|
|
// CHECK: (func_decl "r13756261(_:_:)"
|
|
func r13756261(x: Bool, _ y: Int) -> Int {
|
|
// CHECK: (if_expr
|
|
// CHECK: (call_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (if_expr
|
|
// CHECK: (call_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (if_expr
|
|
// CHECK: (call_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (declref_expr
|
|
return (x) ? y : (x) ? y : (x) ? y : y
|
|
}
|
|
|
|
// CHECK: (func_decl "r13756221(_:_:)"
|
|
func r13756221(x: Bool, _ y: Int) -> Int {
|
|
// CHECK: (if_expr
|
|
// CHECK: (call_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (if_expr
|
|
// CHECK: (call_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (if_expr
|
|
// CHECK: (call_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (declref_expr
|
|
return (x) ? y
|
|
: (x) ? y
|
|
: (x) ? y
|
|
: y
|
|
}
|
|
|
|
// CHECK: (func_decl "telescoping_if(_:_:)"
|
|
func telescoping_if(x: Bool, _ y: Int) -> Int {
|
|
// CHECK: (if_expr
|
|
// CHECK: (call_expr
|
|
// CHECK: (if_expr
|
|
// CHECK: (call_expr
|
|
// CHECK: (if_expr
|
|
// CHECK: (call_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (declref_expr
|
|
return (x) ? (x) ? (x) ? y : y : y : y
|
|
}
|
|
|
|
// Operator with precedence above ? :
|
|
infix operator +>> {
|
|
associativity left
|
|
precedence 110
|
|
}
|
|
|
|
// Operator with precedence below ? :
|
|
infix operator +<< {
|
|
associativity left
|
|
precedence 90
|
|
}
|
|
|
|
// Operator with precedence equal to ? :
|
|
infix operator +== {
|
|
associativity right
|
|
precedence 100
|
|
}
|
|
|
|
func +>> (x: Bool, y: Bool) -> Bool {}
|
|
func +<< (x: Bool, y: Bool) -> Bool {}
|
|
func +== (x: Bool, y: Bool) -> Bool {}
|
|
|
|
// CHECK: (func_decl "prec_above(_:_:_:)"
|
|
func prec_above(x: Bool, _ y: Bool, _ z: Bool) -> Bool {
|
|
// (x +>> y) ? (y +>> z) : ((x +>> y) ? (y +>> z) : (x +>> y))
|
|
// CHECK: (if_expr
|
|
// CHECK: (binary_expr
|
|
// CHECK: (binary_expr
|
|
// CHECK: (if_expr
|
|
// CHECK: (binary_expr
|
|
// CHECK: (binary_expr
|
|
// CHECK: (binary_expr
|
|
return x +>> y ? y +>> z : x +>> y ? y +>> z : x +>> y
|
|
}
|
|
|
|
// CHECK: (func_decl "prec_below(_:_:_:)"
|
|
func prec_below(x: Bool, _ y: Bool, _ z: Bool) -> Bool {
|
|
// The middle arm of the ternary is max-munched, so this is:
|
|
// ((x +<< (y ? (y +<< z) : x)) +<< (y ? (y +<< z) : x)) +<< y
|
|
// CHECK: (binary_expr
|
|
// CHECK: (binary_expr
|
|
// CHECK: (binary_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (if_expr
|
|
// CHECK: (call_expr
|
|
// CHECK: (binary_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (if_expr
|
|
// CHECK: (call_expr
|
|
// CHECK: (binary_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (declref_expr
|
|
return x +<< y ? y +<< z : x +<< y ? y +<< z : x +<< y
|
|
}
|
|
|
|
// CHECK: (func_decl "prec_equal(_:_:_:)"
|
|
func prec_equal(x: Bool, _ y: Bool, _ z: Bool) -> Bool {
|
|
// The middle arm of the ternary is max-munched, so this is:
|
|
// x +== (y ? (y +== z) : (x +== (y ? (y +== z) : (x +== y))))
|
|
// CHECK: (binary_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (if_expr
|
|
// CHECK: (call_expr
|
|
// CHECK: (binary_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (binary_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (if_expr
|
|
// CHECK: (call_expr
|
|
// CHECK: (binary_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (binary_expr
|
|
// CHECK: (declref_expr
|
|
// CHECK: (declref_expr
|
|
return x +== y ? y +== z : x +== y ? y +== z : x +== y
|
|
}
|
|
|