Skip to content

Commit 846f698

Browse files
authored
Merge pull request #8293 from DougGregor/superclass-constraint-uses-gp
2 parents 607732f + bee3f15 commit 846f698

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -631,17 +631,16 @@ static void checkReferencedGenericParams(GenericContext *dc,
631631

632632
auto requirements = sig->getRequirements();
633633
for (auto req : requirements) {
634-
if (req.getKind() == RequirementKind::SameType) {
635-
// Same type requirements may allow for generic
636-
// inference, even if this generic parameter
637-
// is not mentioned in the function signature.
638-
// TODO: Make the test more precise.
639-
auto left = req.getFirstType();
640-
auto right = req.getSecondType();
641-
// For now consider any references inside requirements
642-
// as a possibility to infer the generic type.
643-
left.visit(visitorFn);
644-
right.visit(visitorFn);
634+
switch (req.getKind()) {
635+
case RequirementKind::SameType:
636+
case RequirementKind::Superclass:
637+
req.getSecondType().visit(visitorFn);
638+
LLVM_FALLTHROUGH;
639+
640+
case RequirementKind::Conformance:
641+
case RequirementKind::Layout:
642+
req.getFirstType().visit(visitorFn);
643+
break;
645644
}
646645
}
647646

test/Generics/unbound.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,8 @@ func callfoor20792596<T>(x: T) -> T {
6767
return foor20792596(x) // expected-error {{generic parameter 'T' could not be inferred}}
6868
}
6969

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

0 commit comments

Comments
 (0)