Skip to content

Commit 1eadd44

Browse files
authored
Merge pull request #40440 from nkcsgexi/prefer-swift-type
2 parents fe4d9af + 1781fef commit 1eadd44

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,21 @@ static void diagnoseAmbiguousMemberType(Type baseTy, SourceRange baseRange,
14231423
}
14241424
}
14251425

1426+
static LookupTypeResult preferSwiftTypes(LookupTypeResult results) {
1427+
if (results.size() == 1)
1428+
return results;
1429+
LookupTypeResult newResults;
1430+
for (auto cur: results) {
1431+
if (cur.Member->getClangNode()) {
1432+
continue;
1433+
}
1434+
newResults.addResult(cur);
1435+
}
1436+
if (newResults.size() == 1)
1437+
return newResults;
1438+
return results;
1439+
}
1440+
14261441
/// Resolve the given identifier type representation as a qualified
14271442
/// lookup within the given parent type, returning the type it
14281443
/// references.
@@ -1533,6 +1548,9 @@ static Type resolveNestedIdentTypeComponent(TypeResolution resolution,
15331548
memberTypes = TypeChecker::lookupMemberType(
15341549
DC, parentTy, comp->getNameRef(), lookupOptions);
15351550

1551+
// Prefer Swift types over Clang types.
1552+
memberTypes = preferSwiftTypes(memberTypes);
1553+
15361554
// Name lookup was ambiguous. Complain.
15371555
// FIXME: Could try to apply generic arguments first, and see whether
15381556
// that resolves things. But do we really want that to succeed?

0 commit comments

Comments
 (0)