mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Trailing closures] Diagnose the change in behavior with SE-0268.
SE-0248 changes the backward-scan matching behavior for the unlabeled
trailing closure into a forward scan. In circumstances where this
could silently change the meaning of a call to a particular
function, i.e., when there are two defaulted closure parameters such
that a given closure to match either one of them, produce an warning
that describes the change in behavior. For example:
t4.swift:2:24: warning: since Swift 5.3, unlabeled trailing
closure argument matches parameter 'x' rather than parameter 'z'
trailingClosureSingle2 { $0 }
^
t4.swift:2:24: note: label the argument with 'z' to retain the
pre-Swift 5.3 behavior
trailingClosureSingle2 { $0 }
^
(z: )
t4.swift:2:24: note: label the argument with 'x' to silence this
warning for Swift 5.3 and newer
trailingClosureSingle2 { $0 }
^
(x: )
t4.swift:1:6: note: 'trailingClosureSingle2(x:y:z:)' contains
defaulted closure parameters 'x' and 'z'
func trailingClosureSingle2(x: (Int) -> Int = { $0 } , y: (Int) ->
Int = { $0 }, z: (Int) -> Int = { $0 }) {}
^ ~
This explains the (rare) case where SE-0286 silently changes the
meaning of a program, offering Fix-Its to either restore the
pre-SE-0286 behavior or silence the warning, as appropriate.
This commit is contained in:
@@ -196,7 +196,7 @@ static ConstraintSystem::TypeMatchOptions getDefaultDecompositionOptions(
|
||||
}
|
||||
|
||||
/// Whether the given parameter requires an argument.
|
||||
static bool parameterRequiresArgument(
|
||||
bool swift::parameterRequiresArgument(
|
||||
ArrayRef<AnyFunctionType::Param> params,
|
||||
const ParameterListInfo ¶mInfo,
|
||||
unsigned paramIdx) {
|
||||
|
||||
Reference in New Issue
Block a user