Skip to content

[Type checker] The superclass of a superclass constraint can have type parameters #8293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions lib/Sema/TypeCheckGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,17 +631,16 @@ static void checkReferencedGenericParams(GenericContext *dc,

auto requirements = sig->getRequirements();
for (auto req : requirements) {
if (req.getKind() == RequirementKind::SameType) {
// Same type requirements may allow for generic
// inference, even if this generic parameter
// is not mentioned in the function signature.
// TODO: Make the test more precise.
auto left = req.getFirstType();
auto right = req.getSecondType();
// For now consider any references inside requirements
// as a possibility to infer the generic type.
left.visit(visitorFn);
right.visit(visitorFn);
switch (req.getKind()) {
case RequirementKind::SameType:
case RequirementKind::Superclass:
req.getSecondType().visit(visitorFn);
LLVM_FALLTHROUGH;

case RequirementKind::Conformance:
case RequirementKind::Layout:
req.getFirstType().visit(visitorFn);
break;
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/Generics/unbound.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,8 @@ func callfoor20792596<T>(x: T) -> T {
return foor20792596(x) // expected-error {{generic parameter 'T' could not be inferred}}
}

// <rdar://problem/31181895> parameter "not used in function signature" when part of a superclass constraint
struct X1<T> {
func bar<U>() where T: X2<U> {}
}
class X2<T> {}