Skip to content

Commit 5ef5c6f

Browse files
not perform check if the disjuction choice goes to bridging coercion constraint
1 parent 5660de8 commit 5ef5c6f

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,7 +2807,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
28072807

28082808
// If the types are obviously equivalent, we're done.
28092809
if (desugar1->isEqual(desugar2)) {
2810-
if (locator.getBaseLocator()->isLastElement(ConstraintLocator::PathElementKind::ExplicityTypeCoercion)) {
2810+
if (locator.getBaseLocator()->
2811+
isLastElement(ConstraintLocator::PathElementKind::ExplicityTypeCoercion)) {
28112812
auto *fix = RemoveUnecessaryCoercion::create(*this, type2,
28122813
locator.getBaseLocator());
28132814
recordFix(fix);
@@ -7759,11 +7760,13 @@ void ConstraintSystem::addExplicitConversionConstraint(
77597760
fromType, toType, locatorPtr);
77607761
coerceConstraint->setFavored();
77617762
constraints.push_back(coerceConstraint);
7762-
7763+
7764+
auto bridgingPtr = getConstraintLocator(
7765+
locator.withPathElement(LocatorPathElt::BridgingTypeCoercion()));
77637766
// The source type can be explicitly converted to the destination type.
77647767
Constraint *bridgingConstraint =
77657768
Constraint::create(*this, ConstraintKind::BridgingConversion,
7766-
fromType, toType, locatorPtr);
7769+
fromType, toType, bridgingPtr);
77677770
constraints.push_back(bridgingConstraint);
77687771

77697772
if (allowFixes && shouldAttemptFixes()) {

lib/Sema/ConstraintLocator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void ConstraintLocator::Profile(llvm::FoldingSetNodeID &id, Expr *anchor,
8585
case KeyPathValue:
8686
case KeyPathComponentResult:
8787
case ExplicityTypeCoercion:
88+
case BridgingTypeCoercion:
8889
auto numValues = numNumericValuesInPathElement(elt.getKind());
8990
for (unsigned i = 0; i < numValues; ++i)
9091
id.AddInteger(elt.getValue(i));
@@ -417,6 +418,10 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) {
417418
case ExplicityTypeCoercion:
418419
out << "type coercion";
419420
break;
421+
422+
case BridgingTypeCoercion:
423+
out << "bridging type coercion";
424+
break;
420425
}
421426
}
422427
out << ']';

lib/Sema/ConstraintLocator.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ class ConstraintLocator : public llvm::FoldingSetNode {
139139
KeyPathComponentResult,
140140
/// A explicity type coercion
141141
ExplicityTypeCoercion,
142+
/// A bridging type coercion
143+
BridgingTypeCoercion
142144
};
143145

144146
/// Determine the number of numeric values used for the given path
@@ -173,6 +175,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
173175
case KeyPathValue:
174176
case KeyPathComponentResult:
175177
case ExplicityTypeCoercion:
178+
case BridgingTypeCoercion:
176179
return 0;
177180

178181
case ContextualType:
@@ -245,6 +248,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
245248
case KeyPathValue:
246249
case KeyPathComponentResult:
247250
case ExplicityTypeCoercion:
251+
case BridgingTypeCoercion:
248252
return 0;
249253

250254
case FunctionArgument:
@@ -364,6 +368,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
364368
class OpenedGeneric;
365369
class KeyPathDynamicMember;
366370
class ExplicitTypeCoercion;
371+
class BridgingTypeCoercion;
367372

368373
PathElement(PathElementKind kind)
369374
: storage(encodeStorage(kind, 0)), storedKind(StoredKindAndValue)
@@ -904,6 +909,17 @@ class LocatorPathElt::ExplicitTypeCoercion final : public LocatorPathElt {
904909
}
905910
};
906911

912+
913+
class LocatorPathElt::BridgingTypeCoercion final : public LocatorPathElt {
914+
public:
915+
BridgingTypeCoercion()
916+
: LocatorPathElt(ConstraintLocator::BridgingTypeCoercion) {}
917+
918+
static bool classof(const LocatorPathElt *elt) {
919+
return elt->getKind() == ConstraintLocator::BridgingTypeCoercion;
920+
}
921+
};
922+
907923
/// A simple stack-only builder object that constructs a
908924
/// constraint locator without allocating memory.
909925
///

0 commit comments

Comments
 (0)