@@ -269,6 +269,10 @@ enum class FixKind : uint8_t {
269
269
270
270
// / Unwrap optional base on key path application.
271
271
UnwrapOptionalBaseKeyPathApplication,
272
+
273
+ // / Explicitly specify a label to match trailing closure to a certain
274
+ // / parameter in the call.
275
+ SpecifyLabelToAssociateTrailingClosure,
272
276
};
273
277
274
278
class ConstraintFix {
@@ -1926,6 +1930,34 @@ class UnwrapOptionalBaseKeyPathApplication final : public ContextualMismatch {
1926
1930
ConstraintLocator *locator);
1927
1931
};
1928
1932
1933
+ // / Diagnose situations when solver used old (backward scan) rule
1934
+ // / to match trailing closure to a parameter.
1935
+ // /
1936
+ // / \code
1937
+ // / func multiple_trailing_with_defaults(
1938
+ // / duration: Int,
1939
+ // / animations: (() -> Void)? = nil,
1940
+ // / completion: (() -> Void)? = nil) {}
1941
+ // /
1942
+ // / multiple_trailing_with_defaults(duration: 42) {} // picks `completion:`
1943
+ // / \endcode
1944
+ class SpecifyLabelToAssociateTrailingClosure final : public ConstraintFix {
1945
+ SpecifyLabelToAssociateTrailingClosure (ConstraintSystem &cs,
1946
+ ConstraintLocator *locator)
1947
+ : ConstraintFix(cs, FixKind::SpecifyLabelToAssociateTrailingClosure,
1948
+ locator, /* isWarning=*/ true ) {}
1949
+
1950
+ public:
1951
+ std::string getName () const override {
1952
+ return " specify a label to associate trailing closure with parameter" ;
1953
+ }
1954
+
1955
+ bool diagnose (const Solution &solution, bool asNote = false ) const override ;
1956
+
1957
+ static SpecifyLabelToAssociateTrailingClosure *
1958
+ create (ConstraintSystem &cs, ConstraintLocator *locator);
1959
+ };
1960
+
1929
1961
} // end namespace constraints
1930
1962
} // end namespace swift
1931
1963
0 commit comments