Skip to content

Commit eaf8c6d

Browse files
committed
Conflict resolution and conversion to ConstraintFix class
1 parent 9e0dae5 commit eaf8c6d

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

lib/Sema/CSFix.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ AddAddressOf *AddAddressOf::create(ConstraintSystem &cs,
104104
return new (cs.getAllocator()) AddAddressOf(locator);
105105
}
106106

107+
bool TreatRValueAsLValue::diagnose(Expr *root, const Solution &solution) const {
108+
RValueTreatedAsLValueFailure failure(solution, getLocator());
109+
return failure.diagnose();
110+
}
111+
112+
TreatRValueAsLValue *TreatRValueAsLValue::create(ConstraintSystem &cs,
113+
ConstraintLocator *locator) {
114+
return new (cs.getAllocator()) TreatRValueAsLValue(locator);
115+
}
116+
117+
107118
bool CoerceToCheckedCast::diagnose(Expr *root, const Solution &solution) const {
108119
MissingForcedDowncastFailure failure(root, solution, getLocator());
109120
return failure.diagnose();

lib/Sema/CSFix.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ enum class FixKind : uint8_t {
6868

6969
/// Add a new conformance to the type to satisfy a requirement.
7070
AddConformance,
71+
72+
/// Treat rvalue as lvalue
73+
TreatRValueAsLValue,
7174
};
7275

7376
class ConstraintFix {
@@ -168,6 +171,20 @@ class AddAddressOf final : public ConstraintFix {
168171
static AddAddressOf *create(ConstraintSystem &cs, ConstraintLocator *locator);
169172
};
170173

174+
// Treat rvalue as if it was an lvalue
175+
class TreatRValueAsLValue final : public ConstraintFix {
176+
TreatRValueAsLValue(ConstraintLocator *locator)
177+
: ConstraintFix(FixKind::TreatRValueAsLValue, locator) {}
178+
179+
public:
180+
std::string getName() const override { return "treat rvalue as lvalue"; }
181+
182+
bool diagnose(Expr *root, const Solution &solution) const override;
183+
184+
static TreatRValueAsLValue *create(ConstraintSystem &cs, ConstraintLocator *locator);
185+
};
186+
187+
171188
/// Replace a coercion ('as') with a forced checked cast ('as!').
172189
class CoerceToCheckedCast final : public ConstraintFix {
173190
CoerceToCheckedCast(ConstraintLocator *locator)

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,7 +2446,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
24462446
AddAddressOf::create(*this, getConstraintLocator(locator)));
24472447
} else if (!isTypeVarOrMember1) {
24482448
// If we have a concrete type that's an rvalue, "fix" it.
2449-
conversionsOrFixes.push_back(FixKind::TreatRValueAsLValue);
2449+
conversionsOrFixes.push_back(
2450+
TreatRValueAsLValue::create(*this, getConstraintLocator(locator)));
24502451
}
24512452
}
24522453
}
@@ -4990,7 +4991,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
49904991
auto result = matchTypes(LValueType::get(type1), type2,
49914992
matchKind, subflags, locator);
49924993
if (result == SolutionKind::Solved)
4993-
if (recordFix(fix, locator))
4994+
if (recordFix(fix))
49944995
return SolutionKind::Error;
49954996

49964997
return result;

0 commit comments

Comments
 (0)