Skip to content

Commit 09e0c5a

Browse files
committed
Runtime: Fix shape requirement handling in _checkGenericRequirements()
We would say the shape requirement was always satisfied since we incorrectly checked the left-hand side type twice.
1 parent 0f18125 commit 09e0c5a

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

include/swift/ABI/GenericContext.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,11 @@ class TargetGenericRequirementDescriptor {
183183
return offsetof(typename std::remove_reference<decltype(*this)>::type, Param);
184184
}
185185

186-
/// Retrieve the right-hand type for a SameType or BaseClass requirement.
186+
/// Retrieve the right-hand type for a SameType, BaseClass or SameShape requirement.
187187
llvm::StringRef getMangledTypeName() const {
188188
assert(getKind() == GenericRequirementKind::SameType ||
189-
getKind() == GenericRequirementKind::BaseClass);
189+
getKind() == GenericRequirementKind::BaseClass ||
190+
getKind() == GenericRequirementKind::SameShape);
190191
return swift::Demangle::makeSymbolicMangledNameStringRef(Type.get());
191192
}
192193

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,7 @@ checkGenericPackRequirement(const GenericRequirementDescriptor &req,
15391539

15401540
case GenericRequirementKind::SameShape: {
15411541
auto result = swift::getTypePackByMangledName(
1542-
req.getParam(), extraArguments.data(),
1542+
req.getMangledTypeName(), extraArguments.data(),
15431543
substGenericParam, substWitnessTable);
15441544
if (result.getError())
15451545
return *result.getError();

test/Interpreter/variadic_generic_conditional_conformances.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,23 @@ conformances.test("cast") {
5959
expectEqual(false, cast(G<Bool, Int>(), to: (any P).self))
6060
}
6161

62+
struct Outer<each U> {
63+
struct Inner<each V> {}
64+
}
65+
66+
extension Outer.Inner: P where repeat (repeat (each U, each V)): Any {
67+
static func foobar() -> [String] {
68+
return ["hello"]
69+
}
70+
}
71+
72+
conformances.test("shape") {
73+
expectEqual(true, cast(Outer< >.Inner< >(), to: (any P).self))
74+
expectEqual(true, cast(Outer<Int>.Inner<Bool>(), to: (any P).self))
75+
expectEqual(true, cast(Outer<Int, String>.Inner<Bool, Float>(), to: (any P).self))
76+
77+
expectEqual(false, cast(Outer<Bool>.Inner< >(), to: (any P).self))
78+
expectEqual(false, cast(Outer<Int, Bool>.Inner<String, Float, Character>(), to: (any P).self))
79+
}
80+
6281
runAllTests()

0 commit comments

Comments
 (0)