Skip to content

Commit de7dc62

Browse files
authored
Merge pull request #26177 from DougGregor/property-wrappers-ambig-53164203-5.1
[5.1] [Name lookup] Deduplicate nominal declarations found via resolveTypeDeclsToNominal
2 parents 19e5152 + 0362040 commit de7dc62

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

lib/AST/NameLookup.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,12 +1713,17 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
17131713
SmallVectorImpl<ModuleDecl *> &modulesFound,
17141714
bool &anyObject,
17151715
llvm::SmallPtrSetImpl<TypeAliasDecl *> &typealiases) {
1716+
SmallPtrSet<NominalTypeDecl *, 4> knownNominalDecls;
17161717
TinyPtrVector<NominalTypeDecl *> nominalDecls;
1718+
auto addNominalDecl = [&](NominalTypeDecl *nominal) {
1719+
if (knownNominalDecls.insert(nominal).second)
1720+
nominalDecls.push_back(nominal);
1721+
};
17171722

17181723
for (auto typeDecl : typeDecls) {
17191724
// Nominal type declarations get copied directly.
17201725
if (auto nominalDecl = dyn_cast<NominalTypeDecl>(typeDecl)) {
1721-
nominalDecls.push_back(nominalDecl);
1726+
addNominalDecl(nominalDecl);
17221727
continue;
17231728
}
17241729

@@ -1735,9 +1740,9 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
17351740
auto underlyingNominalReferences
17361741
= resolveTypeDeclsToNominal(evaluator, ctx, underlyingTypeReferences,
17371742
modulesFound, anyObject, typealiases);
1738-
nominalDecls.insert(nominalDecls.end(),
1739-
underlyingNominalReferences.begin(),
1740-
underlyingNominalReferences.end());
1743+
std::for_each(underlyingNominalReferences.begin(),
1744+
underlyingNominalReferences.end(),
1745+
addNominalDecl);
17411746

17421747
// Recognize Swift.AnyObject directly.
17431748
if (typealias->getName().is("AnyObject")) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@propertyWrapper
2+
public struct Wrapper<Value> {
3+
public var wrappedValue: Value
4+
5+
public init(wrappedValue: Value) {
6+
self.wrappedValue = wrappedValue
7+
}
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import property_wrappers_A
2+
3+
public typealias Wrapper = property_wrappers_A.Wrapper
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -I %t -o %t %S/Inputs/property_wrappers_A.swift
3+
// RUN: %target-swift-frontend -emit-module -I %t -o %t %S/Inputs/property_wrappers_B.swift
4+
// RUN: %target-swift-frontend -typecheck -verify -I %t %s
5+
import property_wrappers_A
6+
import property_wrappers_B
7+
8+
struct Test {
9+
@Wrapper var x: Int = 17
10+
}

0 commit comments

Comments
 (0)