Skip to content

Commit

Permalink
[Sema] Error on generic arg lists with different lengths
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cwillmor committed Nov 11, 2015
1 parent b620850 commit da15fbf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,9 @@ ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
// Match up the generic arguments, exactly.
auto args1 = bound1->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) {
switch (matchTypes(args1[i], args2[i], TypeMatchKind::SameType,
TMF_GenerateConstraints,
Expand Down
10 changes: 10 additions & 0 deletions test/Generics/generic_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,13 @@ class Top {}
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-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) {}
}
}

0 comments on commit da15fbf

Please sign in to comment.