Skip to content

Commit ff5dc60

Browse files
committed
[GSB] Infer requirements from protocol inheritance and where clauses.
Fixes rdar://problem/29231937.
1 parent 728831b commit ff5dc60

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4171,7 +4171,7 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
41714171

41724172
auto inheritedReqResult =
41734173
addInheritedRequirements(proto, selfType.getUnresolvedType(), source,
4174-
/*inferForModule=*/nullptr);
4174+
proto->getModuleContext());
41754175
if (isErrorResult(inheritedReqResult))
41764176
return inheritedReqResult;
41774177
}
@@ -4187,7 +4187,7 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
41874187
auto innerSource = FloatingRequirementSource::viaProtocolRequirement(
41884188
source, proto, &req, /*inferred=*/false);
41894189
addRequirement(&req, innerSource, &protocolSubMap,
4190-
/*inferForModule=*/nullptr);
4190+
proto->getModuleContext());
41914191
}
41924192
}
41934193

test/Generics/requirement_inference.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-typecheck-verify-swift -typecheck %s -verify
2-
// RUN: %target-typecheck-verify-swift -typecheck -debug-generic-signatures %s > %t.dump 2>&1
1+
// RUN: %target-typecheck-verify-swift -typecheck -verify
2+
// RUN: %target-typecheck-verify-swift -typecheck -debug-generic-signatures > %t.dump 2>&1
33
// RUN: %FileCheck %s < %t.dump
44

55
protocol P1 {
@@ -487,3 +487,14 @@ extension X1WithP2 {
487487
_ = X5<T>() // FIXME: expected-error{{type 'T' does not conform to protocol 'P2'}}
488488
}
489489
}
490+
491+
// Inference from protocol inheritance clauses.
492+
typealias ExistentialP4WithP2Assoc<T: P4> = P4 where T.P4Assoc : P2
493+
494+
protocol P37 : ExistentialP4WithP2Assoc<Self> { }
495+
496+
extension P37 {
497+
func f() {
498+
_ = X5<P4Assoc>() // requires P2
499+
}
500+
}

0 commit comments

Comments
 (0)