Skip to content

Commit f173124

Browse files
authored
Merge pull request #26174 from DougGregor/property-wrappers-ambig-53164203
[Name lookup] Deduplicate nominal declarations found via resolveTypeDeclsToNominal
2 parents ccc70b7 + 4b1fff9 commit f173124

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
@@ -1734,12 +1734,17 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
17341734
SmallVectorImpl<ModuleDecl *> &modulesFound,
17351735
bool &anyObject,
17361736
llvm::SmallPtrSetImpl<TypeAliasDecl *> &typealiases) {
1737+
SmallPtrSet<NominalTypeDecl *, 4> knownNominalDecls;
17371738
TinyPtrVector<NominalTypeDecl *> nominalDecls;
1739+
auto addNominalDecl = [&](NominalTypeDecl *nominal) {
1740+
if (knownNominalDecls.insert(nominal).second)
1741+
nominalDecls.push_back(nominal);
1742+
};
17381743

17391744
for (auto typeDecl : typeDecls) {
17401745
// Nominal type declarations get copied directly.
17411746
if (auto nominalDecl = dyn_cast<NominalTypeDecl>(typeDecl)) {
1742-
nominalDecls.push_back(nominalDecl);
1747+
addNominalDecl(nominalDecl);
17431748
continue;
17441749
}
17451750

@@ -1756,9 +1761,9 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
17561761
auto underlyingNominalReferences
17571762
= resolveTypeDeclsToNominal(evaluator, ctx, underlyingTypeReferences,
17581763
modulesFound, anyObject, typealiases);
1759-
nominalDecls.insert(nominalDecls.end(),
1760-
underlyingNominalReferences.begin(),
1761-
underlyingNominalReferences.end());
1764+
std::for_each(underlyingNominalReferences.begin(),
1765+
underlyingNominalReferences.end(),
1766+
addNominalDecl);
17621767

17631768
// Recognize Swift.AnyObject directly.
17641769
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)