Skip to content

Commit 527a519

Browse files
committed
AST: TypeMatcher needs to recurse into OpaqueTypeArchetypeTypes
Fixes https://bugs.swift.org/browse/SR-16040.
1 parent ac7efc1 commit 527a519

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

include/swift/AST/TypeMatcher.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,41 @@ class TypeMatcher {
229229
}
230230

231231
TRIVIAL_CASE(ModuleType)
232-
TRIVIAL_CASE(ArchetypeType)
232+
233+
bool visitArchetypeType(CanArchetypeType firstArchetype,
234+
Type secondType,
235+
Type sugaredFirstType) {
236+
if (auto firstOpaqueArchetype = dyn_cast<OpaqueTypeArchetypeType>(firstArchetype)) {
237+
if (auto secondOpaqueArchetype = secondType->getAs<OpaqueTypeArchetypeType>()) {
238+
if (firstOpaqueArchetype->getDecl() == secondOpaqueArchetype->getDecl()) {
239+
auto firstSubMap = firstOpaqueArchetype->getSubstitutions();
240+
auto secondSubMap = secondOpaqueArchetype->getSubstitutions();
241+
assert(firstSubMap.getReplacementTypes().size() ==
242+
secondSubMap.getReplacementTypes().size());
243+
244+
for (unsigned i : indices(firstSubMap.getReplacementTypes())) {
245+
auto firstSubstType = firstSubMap.getReplacementTypes()[i];
246+
auto secondSubstType = secondSubMap.getReplacementTypes()[i];
247+
248+
if (!this->visit(firstSubstType->getCanonicalType(),
249+
secondSubstType, firstSubstType))
250+
return false;
251+
}
252+
253+
return true;
254+
}
255+
}
256+
}
257+
258+
// FIXME: Once OpenedArchetypeType stores substitutions, do something
259+
// similar to the above.
260+
261+
if (firstArchetype->isEqual(secondType))
262+
return true;
263+
264+
265+
return mismatch(firstArchetype.getPointer(), secondType, sugaredFirstType);
266+
}
233267

234268
bool visitDynamicSelfType(CanDynamicSelfType firstDynamicSelf,
235269
Type secondType,

test/Generics/sr16040.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %target-swift-frontend -typecheck %s -disable-availability-checking -debug-generic-signatures 2>&1 | %FileCheck %s
2+
3+
public protocol View {
4+
associatedtype Body : View
5+
var body: Body { get }
6+
}
7+
8+
public struct Text : View {
9+
public init(_: String) {}
10+
public var body: Self { return self }
11+
}
12+
13+
public protocol DisplayableValue {}
14+
15+
public protocol SingleValueDisplay: View {
16+
associatedtype DisplayedValue
17+
init (_ singleValue: DisplayedValue)
18+
var displayedValue: DisplayedValue { get }
19+
}
20+
21+
// CHECK-LABEL: .RawDisplayableValue@
22+
// CHECK-NEXT: Requirement signature: <Self where Self : DisplayableValue, Self == Self.[RawDisplayableValue]RawDisplay.[SingleValueDisplay]DisplayedValue, Self.[RawDisplayableValue]RawDisplay : SingleValueDisplay>
23+
public protocol RawDisplayableValue: DisplayableValue {
24+
associatedtype RawDisplay: SingleValueDisplay
25+
where RawDisplay.DisplayedValue == Self
26+
}
27+
28+
// CHECK-LABEL: .RawTextDisplayableValue@
29+
// CHECK-NEXT: Requirement signature: <Self where Self : CustomStringConvertible, Self : RawDisplayableValue, Self.[RawDisplayableValue]RawDisplay == RawTextDisplay<Self>>
30+
public protocol RawTextDisplayableValue: RawDisplayableValue
31+
where Self: CustomStringConvertible,
32+
RawDisplay == RawTextDisplay<Self> { }
33+
34+
public struct RawTextDisplay <Value: CustomStringConvertible>: SingleValueDisplay {
35+
public var displayedValue: Value
36+
37+
public init (_ singleValue: Value) {
38+
self.displayedValue = singleValue
39+
}
40+
41+
public var body: some View {
42+
Text(displayedValue.description)
43+
}
44+
}

0 commit comments

Comments
 (0)