@@ -450,6 +450,10 @@ enum class FixKind : uint8_t {
450450
451451 // / Ignore missing 'each' keyword before value pack reference.
452452 IgnoreMissingEachKeyword,
453+
454+ // / Ignore the fact that member couldn't be referenced within init accessor
455+ // / because its name doesn't appear in 'initializes' or 'accesses' attributes.
456+ AllowInvalidMemberReferenceInInitAccessor,
453457};
454458
455459class ConstraintFix {
@@ -3566,6 +3570,39 @@ class IgnoreMissingEachKeyword final : public ConstraintFix {
35663570 }
35673571};
35683572
3573+ class AllowInvalidMemberReferenceInInitAccessor final : public ConstraintFix {
3574+ DeclNameRef MemberName;
3575+
3576+ AllowInvalidMemberReferenceInInitAccessor (ConstraintSystem &cs,
3577+ DeclNameRef memberName,
3578+ ConstraintLocator *locator)
3579+ : ConstraintFix(cs, FixKind::AllowInvalidMemberReferenceInInitAccessor,
3580+ locator),
3581+ MemberName (memberName) {}
3582+
3583+ public:
3584+ std::string getName () const override {
3585+ llvm::SmallVector<char , 16 > scratch;
3586+ auto memberName = MemberName.getString (scratch);
3587+ return " allow reference to member '" + memberName.str () +
3588+ " ' in init accessor" ;
3589+ }
3590+
3591+ bool diagnose (const Solution &solution, bool asNote = false ) const override ;
3592+
3593+ bool diagnoseForAmbiguity (CommonFixesArray commonFixes) const override {
3594+ return diagnose (*commonFixes.front ().first );
3595+ }
3596+
3597+ static AllowInvalidMemberReferenceInInitAccessor *
3598+ create (ConstraintSystem &cs, DeclNameRef memberName,
3599+ ConstraintLocator *locator);
3600+
3601+ static bool classof (const ConstraintFix *fix) {
3602+ return fix->getKind () == FixKind::AllowInvalidMemberReferenceInInitAccessor;
3603+ }
3604+ };
3605+
35693606} // end namespace constraints
35703607} // end namespace swift
35713608
0 commit comments