Skip to content

Commit ac1ab1d

Browse files
committed
[CSFix] Fix inability to infer contextual base type for member ref
1 parent 8b1debf commit ac1ab1d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/Sema/CSFix.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,3 +1048,13 @@ std::string TreatEphemeralAsNonEphemeral::getName() const {
10481048
name += ::getName(ConversionKind);
10491049
return name;
10501050
}
1051+
1052+
bool SpecifyBaseTypeForContextualMember::diagnose(bool asNote) const {
1053+
return false;
1054+
}
1055+
1056+
SpecifyBaseTypeForContextualMember *SpecifyBaseTypeForContextualMember::create(
1057+
ConstraintSystem &cs, DeclName member, ConstraintLocator *locator) {
1058+
return new (cs.getAllocator())
1059+
SpecifyBaseTypeForContextualMember(cs, member, locator);
1060+
}

lib/Sema/CSFix.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ enum class FixKind : uint8_t {
223223
/// Allow an ephemeral argument conversion for a parameter marked as being
224224
/// non-ephemeral.
225225
TreatEphemeralAsNonEphemeral,
226+
227+
/// Base type in reference to the contextual member e.g. `.foo` couldn't be
228+
/// inferred and has to be specified explicitly.
229+
SpecifyBaseTypeForContextualMember,
226230
};
227231

228232
class ConstraintFix {
@@ -1535,6 +1539,27 @@ class TreatEphemeralAsNonEphemeral final : public AllowArgumentMismatch {
15351539
bool downgradeToWarning);
15361540
};
15371541

1542+
class SpecifyBaseTypeForContextualMember final : public ConstraintFix {
1543+
DeclName MemberName;
1544+
1545+
SpecifyBaseTypeForContextualMember(ConstraintSystem &cs, DeclName member,
1546+
ConstraintLocator *locator)
1547+
: ConstraintFix(cs, FixKind::SpecifyBaseTypeForContextualMember, locator),
1548+
MemberName(member) {}
1549+
1550+
public:
1551+
std::string getName() const {
1552+
const auto baseName = MemberName.getBaseName();
1553+
return "specify base type in reference to member '" +
1554+
baseName.userFacingName().str() + "'";
1555+
}
1556+
1557+
bool diagnose(bool asNote = false) const;
1558+
1559+
static SpecifyBaseTypeForContextualMember *
1560+
create(ConstraintSystem &cs, DeclName member, ConstraintLocator *locator);
1561+
};
1562+
15381563
} // end namespace constraints
15391564
} // end namespace swift
15401565

0 commit comments

Comments
 (0)