mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Sema] Error on generic arg lists with different lengths
Don't assert that generic arg lists have the same lengths. We don't currently allow nested generics, but we try to type-check anyway, and one of the effects is sticking the generic params for both the outer and inner classes on the inner type. Instead, just error out. <rdar://problem/21967211>
This commit is contained in:
@@ -1038,7 +1038,9 @@ ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
|
|||||||
// Match up the generic arguments, exactly.
|
// Match up the generic arguments, exactly.
|
||||||
auto args1 = bound1->getGenericArgs();
|
auto args1 = bound1->getGenericArgs();
|
||||||
auto args2 = bound2->getGenericArgs();
|
auto args2 = bound2->getGenericArgs();
|
||||||
assert(args1.size() == args2.size() && "Mismatched generic args");
|
if (args1.size() != args2.size()) {
|
||||||
|
return SolutionKind::Error;
|
||||||
|
}
|
||||||
for (unsigned i = 0, n = args1.size(); i != n; ++i) {
|
for (unsigned i = 0, n = args1.size(); i != n; ++i) {
|
||||||
switch (matchTypes(args1[i], args2[i], TypeMatchKind::SameType,
|
switch (matchTypes(args1[i], args2[i], TypeMatchKind::SameType,
|
||||||
TMF_GenerateConstraints,
|
TMF_GenerateConstraints,
|
||||||
|
|||||||
@@ -312,3 +312,13 @@ class Top {}
|
|||||||
class Bottom<T : Bottom<Top>> {} // expected-error 2{{type may not reference itself as a requirement}}
|
class Bottom<T : Bottom<Top>> {} // expected-error 2{{type may not reference itself as a requirement}}
|
||||||
// expected-error@-1{{Bottom' requires that 'Top' inherit from 'Bottom<Top>'}}
|
// expected-error@-1{{Bottom' requires that 'Top' inherit from 'Bottom<Top>'}}
|
||||||
// expected-note@-2{{requirement specified as 'T' : 'Bottom<Top>' [with T = Top]}}
|
// expected-note@-2{{requirement specified as 'T' : 'Bottom<Top>' [with T = Top]}}
|
||||||
|
|
||||||
|
class X6<T> {
|
||||||
|
let d: D<T>
|
||||||
|
init(_ value: T) {
|
||||||
|
d = D(value) // expected-error{{cannot invoke initializer for type 'X6<T>.D<_, _>' with an argument list of type '(T)'}} expected-note{{expected an argument list of type '(T2)'}}
|
||||||
|
}
|
||||||
|
class D<T2> { // expected-error{{generic type 'D' nested in type 'X6' is not allowed}}
|
||||||
|
init(_ value: T2) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user