Skip to content

Commit 4f97ef0

Browse files
committed
[ConstraintSystem] Add a helper to determine whether locator is for argument to C/ObjC imported decl
1 parent 3a41f7a commit 4f97ef0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5214,6 +5214,10 @@ class ConstraintSystem {
52145214
/// as the anchor, and a path to the argument at index `0`.
52155215
ConstraintLocator *getArgumentLocator(Expr *expr);
52165216

5217+
/// Determine whether given locator represents an argument to declaration
5218+
/// imported from C/ObjectiveC.
5219+
bool isArgumentOfImportedDecl(ConstraintLocatorBuilder locator);
5220+
52175221
SWIFT_DEBUG_DUMP;
52185222
SWIFT_DEBUG_DUMPER(dump(Expr *));
52195223

lib/Sema/ConstraintSystem.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4999,6 +4999,22 @@ bool constraints::isArgumentOfReferenceEqualityOperator(
49994999
isOperatorArgument(locator, "!==");
50005000
}
50015001

5002+
bool ConstraintSystem::isArgumentOfImportedDecl(
5003+
ConstraintLocatorBuilder locator) {
5004+
auto last = locator.last();
5005+
if (!(last && last->is<LocatorPathElt::ApplyArgToParam>()))
5006+
return false;
5007+
5008+
auto *application = getCalleeLocator(getConstraintLocator(locator));
5009+
5010+
auto overload = findSelectedOverloadFor(application);
5011+
if (!(overload && overload->choice.isDecl()))
5012+
return false;
5013+
5014+
auto *choice = overload->choice.getDecl();
5015+
return choice->hasClangNode();
5016+
}
5017+
50025018
ConversionEphemeralness
50035019
ConstraintSystem::isConversionEphemeral(ConversionRestrictionKind conversion,
50045020
ConstraintLocatorBuilder locator) {

0 commit comments

Comments
 (0)