@@ -398,6 +398,10 @@ enum class FixKind : uint8_t {
398
398
// / Coerce a result type of a call to a particular existential type
399
399
// / by adding `as any <#Type#>`.
400
400
AddExplicitExistentialCoercion,
401
+
402
+ // / For example `.a(let x), .b(let x)` where `x` gets bound to different
403
+ // / types.
404
+ RenameConflictingPatternVariables,
401
405
};
402
406
403
407
class ConstraintFix {
@@ -3016,6 +3020,50 @@ class AddExplicitExistentialCoercion final : public ConstraintFix {
3016
3020
ConstraintLocator *locator);
3017
3021
};
3018
3022
3023
+ class RenameConflictingPatternVariables final
3024
+ : public ConstraintFix,
3025
+ private llvm::TrailingObjects<RenameConflictingPatternVariables,
3026
+ VarDecl *> {
3027
+ friend TrailingObjects;
3028
+
3029
+ Type ExpectedType;
3030
+ unsigned NumConflicts;
3031
+
3032
+ RenameConflictingPatternVariables (ConstraintSystem &cs, Type expectedTy,
3033
+ ArrayRef<VarDecl *> conflicts,
3034
+ ConstraintLocator *locator)
3035
+ : ConstraintFix(cs, FixKind::RenameConflictingPatternVariables, locator),
3036
+ ExpectedType (expectedTy), NumConflicts(conflicts.size()) {
3037
+ std::uninitialized_copy (conflicts.begin (), conflicts.end (),
3038
+ getConflictingBuffer ().begin ());
3039
+ }
3040
+
3041
+ MutableArrayRef<VarDecl *> getConflictingBuffer () {
3042
+ return {getTrailingObjects<VarDecl *>(), NumConflicts};
3043
+ }
3044
+
3045
+ public:
3046
+ std::string getName () const override { return " rename pattern variables" ; }
3047
+
3048
+ ArrayRef<VarDecl *> getConflictingVars () const {
3049
+ return {getTrailingObjects<VarDecl *>(), NumConflicts};
3050
+ }
3051
+
3052
+ bool diagnose (const Solution &solution, bool asNote = false ) const override ;
3053
+
3054
+ bool diagnoseForAmbiguity (CommonFixesArray commonFixes) const override {
3055
+ return diagnose (*commonFixes.front ().first );
3056
+ }
3057
+
3058
+ static RenameConflictingPatternVariables *
3059
+ create (ConstraintSystem &cs, Type expectedTy, ArrayRef<VarDecl *> conflicts,
3060
+ ConstraintLocator *locator);
3061
+
3062
+ static bool classof (ConstraintFix *fix) {
3063
+ return fix->getKind () == FixKind::RenameConflictingPatternVariables;
3064
+ }
3065
+ };
3066
+
3019
3067
} // end namespace constraints
3020
3068
} // end namespace swift
3021
3069
0 commit comments