Skip to content

Commit e169361

Browse files
committed
[Type checker] Handle literals based on superclass constraints.
When we form a literal whose type is a type parameter where the literal conformance comes from a superclass constraint of that type parameter, make sure we can property extract the type witness we need. Fixes SR-7551 / rdar://problem/39860617. (cherry picked from commit 8dbdf7f)
1 parent 218d6f0 commit e169361

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lib/AST/ProtocolConformance.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,6 @@ ProtocolConformanceRef::getTypeWitnessByName(Type type,
134134
ProtocolConformanceRef conformance,
135135
Identifier name,
136136
LazyResolver *resolver) {
137-
// For an archetype, retrieve the nested type with the appropriate
138-
// name. There are no conformance tables.
139-
if (auto archetype = type->getAs<ArchetypeType>()) {
140-
return archetype->getNestedType(name);
141-
}
142-
143137
// Find the named requirement.
144138
AssociatedTypeDecl *assocType = nullptr;
145139
auto members = conformance.getRequirement()->lookupDirect(name);
@@ -153,8 +147,15 @@ ProtocolConformanceRef::getTypeWitnessByName(Type type,
153147
if (!assocType)
154148
return nullptr;
155149

156-
if (conformance.isAbstract())
150+
if (conformance.isAbstract()) {
151+
// For an archetype, retrieve the nested type with the appropriate
152+
// name. There are no conformance tables.
153+
if (auto archetype = type->getAs<ArchetypeType>()) {
154+
return archetype->getNestedType(name);
155+
}
156+
157157
return DependentMemberType::get(type, assocType);
158+
}
158159

159160
auto concrete = conformance.getConcrete();
160161
if (!concrete->hasTypeWitness(assocType, resolver)) {

test/Constraints/generic_super_constraint.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ func bar<T, U>(_ x: U, y: T) -> (Derived, Int) where U: Base<T>, U: Derived {
1717
// expected-error@+1{{cannot convert return expression}}
1818
return (x, y)
1919
}
20+
21+
// SR-7551 captures a crash on this code.
22+
class IntegerClass : ExpressibleByIntegerLiteral, Equatable {
23+
required init(integerLiteral value: Int) { }
24+
static func ==(lhs: IntegerClass, rhs: IntegerClass) -> Bool { return true }
25+
}
26+
27+
func foo<T: IntegerClass>(_ num: T) { let x = num != 0 }

0 commit comments

Comments
 (0)