Skip to content

Commit afc3408

Browse files
committed
[ConstraintSystem] De-prioritize missing member fix when base is contextual
Impact is higher if the base is expected to be inferred from context, because a failure to find a member ultimately means that base type is not a match in this case.
1 parent c20e4ac commit afc3408

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5397,7 +5397,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
53975397

53985398
auto *fix =
53995399
DefineMemberBasedOnUse::create(*this, baseTy, member, locator);
5400-
if (recordFix(fix))
5400+
// Impact is higher if the base is expected to be inferred from context,
5401+
// because a failure to find a member ultimately means that base type is
5402+
// not a match in this case.
5403+
auto impact =
5404+
locator->findLast<LocatorPathElt::UnresolvedMember>() ? 2 : 1;
5405+
if (recordFix(fix, impact))
54015406
return SolutionKind::Error;
54025407

54035408
// Allow member type to default to `Any` to make it possible to form

lib/Sema/ConstraintLocator.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
359359
class GenericParameter;
360360
class OpenedGeneric;
361361
class KeyPathDynamicMember;
362+
class UnresolvedMember;
362363

363364
PathElement(PathElementKind kind)
364365
: storage(encodeStorage(kind, 0)), storedKind(StoredKindAndValue)
@@ -910,6 +911,15 @@ class LocatorPathElt::KeyPathDynamicMember final : public LocatorPathElt {
910911
}
911912
};
912913

914+
class LocatorPathElt::UnresolvedMember final : public LocatorPathElt {
915+
public:
916+
UnresolvedMember() : LocatorPathElt(PathElementKind::UnresolvedMember, 0) {}
917+
918+
static bool classof(const LocatorPathElt *elt) {
919+
return elt->getKind() == ConstraintLocator::UnresolvedMember;
920+
}
921+
};
922+
913923
/// A simple stack-only builder object that constructs a
914924
/// constraint locator without allocating memory.
915925
///

0 commit comments

Comments
 (0)