Skip to content

Commit f045350

Browse files
committed
[CS] Clean up dynamic member overload choice checking
Add `OverloadChoice::isAnyDynamicMemberLookup`, and use it to clean up a couple of places.
1 parent 3d4006e commit f045350

File tree

4 files changed

+13
-24
lines changed

4 files changed

+13
-24
lines changed

include/swift/Sema/OverloadChoice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ class OverloadChoice {
274274
return BaseAndDeclKind.getInt() == IsFallbackDeclViaUnwrappedOptional;
275275
}
276276

277+
/// Whether this choice is for any kind of dynamic member lookup.
278+
bool isAnyDynamicMemberLookup() const {
279+
return getKind() == OverloadChoiceKind::DynamicMemberLookup ||
280+
isKeyPathDynamicMemberLookup();
281+
}
282+
277283
/// Get the name of the overload choice.
278284
DeclName getName() const;
279285

lib/Sema/CSApply.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,10 +3314,7 @@ namespace {
33143314
}
33153315

33163316
Type getTypeOfDynamicMemberIndex(const SelectedOverload &overload) {
3317-
assert(overload.choice.getKind() ==
3318-
OverloadChoiceKind::DynamicMemberLookup ||
3319-
overload.choice.getKind() ==
3320-
OverloadChoiceKind::KeyPathDynamicMemberLookup);
3317+
assert(overload.choice.isAnyDynamicMemberLookup());
33213318

33223319
auto declTy = solution.simplifyType(overload.openedFullType);
33233320
auto subscriptTy = declTy->castTo<FunctionType>()->getResult();
@@ -3438,8 +3435,7 @@ namespace {
34383435
return nullptr;
34393436
}
34403437

3441-
if (overload->choice.getKind() ==
3442-
OverloadChoiceKind::KeyPathDynamicMemberLookup) {
3438+
if (overload->choice.isKeyPathDynamicMemberLookup()) {
34433439
return buildDynamicMemberLookupRef(
34443440
expr, expr->getBase(), expr->getArgs()->getStartLoc(), SourceLoc(),
34453441
*overload, memberLocator);
@@ -4803,11 +4799,7 @@ namespace {
48034799
continue;
48044800
}
48054801

4806-
isDynamicMember =
4807-
foundDecl->choice.getKind() ==
4808-
OverloadChoiceKind::DynamicMemberLookup ||
4809-
foundDecl->choice.getKind() ==
4810-
OverloadChoiceKind::KeyPathDynamicMemberLookup;
4802+
isDynamicMember = foundDecl->choice.isAnyDynamicMemberLookup();
48114803

48124804
// If this was a @dynamicMemberLookup property, then we actually
48134805
// form a subscript reference, so switch the kind.
@@ -5087,17 +5079,10 @@ namespace {
50875079
// through the subscript(dynamicMember:) member, restore the
50885080
// openedType and origComponent to its full reference as if the user
50895081
// wrote out the subscript manually.
5090-
bool forDynamicLookup =
5091-
overload.choice.getKind() ==
5092-
OverloadChoiceKind::DynamicMemberLookup ||
5093-
overload.choice.getKind() ==
5094-
OverloadChoiceKind::KeyPathDynamicMemberLookup;
5095-
5096-
if (forDynamicLookup) {
5082+
if (overload.choice.isAnyDynamicMemberLookup()) {
50975083
auto indexType = getTypeOfDynamicMemberIndex(overload);
50985084
Expr *argExpr = nullptr;
5099-
if (overload.choice.getKind() ==
5100-
OverloadChoiceKind::KeyPathDynamicMemberLookup) {
5085+
if (overload.choice.isKeyPathDynamicMemberLookup()) {
51015086
argExpr = buildKeyPathDynamicMemberArgExpr(
51025087
indexType->castTo<BoundGenericType>(), componentLoc, memberLoc);
51035088
} else {

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,8 +1619,7 @@ bool RValueTreatedAsLValueFailure::diagnoseAsError() {
16191619
OverloadChoiceKind::DynamicMemberLookup)
16201620
subElementDiagID = diag::assignment_dynamic_property_has_immutable_base;
16211621

1622-
if (resolvedOverload->choice.getKind() ==
1623-
OverloadChoiceKind::KeyPathDynamicMemberLookup) {
1622+
if (resolvedOverload->choice.isKeyPathDynamicMemberLookup()) {
16241623
if (!getType(member->getBase(), /*wantRValue=*/false)->hasLValueType())
16251624
subElementDiagID =
16261625
diag::assignment_dynamic_property_has_immutable_base;

lib/Sema/CSSolver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,8 +1605,7 @@ ConstraintSystem::filterDisjunction(
16051605
// be attempted in-place because that would also try to operate on that
16061606
// constraint, so instead let's keep the disjunction, but disable all
16071607
// unviable choices.
1608-
if (choice->getOverloadChoice().getKind() ==
1609-
OverloadChoiceKind::KeyPathDynamicMemberLookup) {
1608+
if (choice->getOverloadChoice().isKeyPathDynamicMemberLookup()) {
16101609
// Early simplification of the "keypath dynamic member lookup" choice
16111610
// is impossible because it requires constraints associated with
16121611
// subscript index expression to be present.

0 commit comments

Comments
 (0)