File tree Expand file tree Collapse file tree 2 files changed +25
-12
lines changed Expand file tree Collapse file tree 2 files changed +25
-12
lines changed Original file line number Diff line number Diff line change @@ -2239,15 +2239,22 @@ static Type getMemberForBaseType(Module *module,
2239
2239
// If the parent is an archetype, extract the child archetype with the
2240
2240
// given name.
2241
2241
if (auto archetypeParent = substBase->getAs <ArchetypeType>()) {
2242
- if (!archetypeParent->hasNestedType (name)) {
2243
- const auto parent = archetypeParent->getParent ();
2244
- if (!parent)
2245
- return ErrorType::get (module ->getASTContext ());
2246
- if (parent->isSelfDerived ())
2247
- return parent->getNestedTypeValue (name);
2242
+ if (archetypeParent->hasNestedType (name))
2243
+ return archetypeParent->getNestedTypeValue (name);
2244
+
2245
+ if (auto parent = archetypeParent->getParent ()) {
2246
+ // If the archetype doesn't have the requested type and the parent is not
2247
+ // self derived, error out
2248
+ return parent->isSelfDerived () ? parent->getNestedTypeValue (name)
2249
+ : ErrorType::get (module ->getASTContext ());
2250
+ }
2251
+
2252
+ // If looking for an associated type and the archetype is constrained to a
2253
+ // class, continue to the default associated type lookup
2254
+ if (!assocType || !archetypeParent->getSuperclass ()) {
2255
+ // else just error out
2256
+ return ErrorType::get (module ->getASTContext ());
2248
2257
}
2249
-
2250
- return archetypeParent->getNestedTypeValue (name);
2251
2258
}
2252
2259
2253
2260
// If the parent is a type variable, retrieve its member type
Original file line number Diff line number Diff line change @@ -4,18 +4,18 @@ protocol Runcible {
4
4
associatedtype Runcee
5
5
}
6
6
7
- class Mince {
8
- init ( ) { }
7
+ class Mince {
8
+ init ( ) { }
9
9
}
10
10
11
11
class Spoon : Runcible {
12
- init ( ) { }
12
+ init ( ) { }
13
13
14
14
typealias Runcee = Mince
15
15
}
16
16
17
17
class Owl < T: Runcible > {
18
- init ( ) { }
18
+ init ( ) { }
19
19
20
20
func eat( what: T . Runcee , with: T ) { }
21
21
}
@@ -31,3 +31,9 @@ func owl2() -> Owl<Spoon> {
31
31
func owl3( ) {
32
32
Owl < Spoon > ( ) . eat ( Mince ( ) , with: Spoon ( ) )
33
33
}
34
+
35
+ // "Can't access associated types through class-constrained generic parameters"
36
+ // (https://bugs.swift.org/browse/SR-726)
37
+ func spoon< S: Spoon > ( s: S ) {
38
+ let _: S . Runcee ? = nil
39
+ }
You can’t perform that action at this time.
0 commit comments