Skip to content

Commit 8b59660

Browse files
committed
GSB: Don't infer requirements from type constructors in a protocol inheritance clause
This enabled a gross idiom that should not have been allowed in the first place: typealias G<T> = Any where T : P protocol P {} protocol Q : G<Self> {} // Q inherits from P now! I'd like to ban this, assuming nothing is actually relying on this behavior.
1 parent fc6f9e0 commit 8b59660

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4012,7 +4012,7 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
40124012
// Add all of the inherited protocol requirements, recursively.
40134013
auto inheritedReqResult =
40144014
addInheritedRequirements(proto, selfType.getUnresolvedType(), source,
4015-
proto->getModuleContext());
4015+
nullptr);
40164016
if (isErrorResult(inheritedReqResult))
40174017
return inheritedReqResult;
40184018
}

test/Generics/requirement_inference.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,15 @@ extension X1WithP2MoreArgs {
508508
}
509509
}
510510

511-
// Inference from protocol inheritance clauses.
511+
// Inference from protocol inheritance clauses is not allowed.
512512
typealias ExistentialP4WithP2Assoc<T: P4> = P4 where T.P4Assoc : P2
513513

514514
protocol P37 : ExistentialP4WithP2Assoc<Self> { }
515+
// expected-error@-1 {{type 'Self.P4Assoc' does not conform to protocol 'P2'}}
515516

516517
extension P37 {
517518
func f() {
518-
_ = X5<P4Assoc>() // requires P2
519+
_ = X5<P4Assoc>()
520+
// expected-error@-1 {{type 'Self.P4Assoc' does not conform to protocol 'P2'}}
519521
}
520522
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// RUN: %target-swift-frontend %s -emit-ir -o /dev/null
1+
// RUN: %target-typecheck-verify-swift
22

33
protocol P {
44
associatedtype A
55
}
66
struct Straint<C: P> where C.A : P {
77
typealias X = Any
88
}
9-
protocol Q : Straint<Self>.X {}
9+
protocol Q : Straint<Self>.X {} // expected-error {{type 'Self' does not conform to protocol 'P'}}

0 commit comments

Comments
 (0)