Skip to content

Commit a2a663c

Browse files
committed
[Name lookup] Narrow shadowing to non-member types.
Narrow the recently-introduced shadowing rule for types so that it only applies to non-member types. Member types lack a reasonable syntax for specifying precisely which module to look into, and there are a few use cases where the type checker will pick a type that would be shadowed by the new rule. Fixes a source-compatibility regression introduced by the shadowing rule.
1 parent fc7eb0d commit a2a663c

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/AST/NameLookup.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ static void recordShadowedDecls(ArrayRef<ValueDecl *> decls,
377377
// type. This is layering a partial fix upon a total hack.
378378
if (auto asd = dyn_cast<AbstractStorageDecl>(decl))
379379
signature = asd->getOverloadSignatureType();
380+
} else if (decl->getDeclContext()->isTypeContext()) {
381+
// Do not apply shadowing rules for member types.
382+
continue;
380383
}
381384

382385
// Record this declaration based on its signature.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class RootClass {
2+
}
3+
4+
public class SubClass: RootClass {
5+
public typealias Member = Int
6+
}
7+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/MemberTypesInClasses.swift
3+
// RUN: %target-swift-frontend -typecheck %s -I %t -verify
4+
5+
import MemberTypesInClasses
6+
7+
protocol P {
8+
associatedtype Member
9+
}
10+
11+
extension RootClass: P {
12+
typealias Member = SubClass.Member
13+
}
14+
15+

0 commit comments

Comments
 (0)