GSB: Teach 'derived via concrete' computation about superclass constraints [5.3] #32489
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Under certain circumstances, introducing a concrete same-type or
superclass constraint can re-introduce conformance constraints
which were previously redundant.
For example, consider this code, which we correctly support today:
The constraint
T == SomeClass<U>
makes the outer constraintT : P
redundant, because SomeClass already conforms to P.It also introduces an implied same-type constraint
U == T.T
.However, whereas
T : P
together withU == T.T
makeU : Q
redundant, the introduction of the constraint
T == SomeClass<U>
removes
'T : P
, so we re-introduce an explicit constraintU : Q
in order to get a valid generic signature.
This code path did the right thing for constraints derived via
concrete same-type constraints, but it did not handle superclass
constraints.
As a result, this case was broken:
This is the same example as above, except T is related via a
superclass constraint to
SomeClass<U>
, instead of via a concretesame-type constraint.
The subtlety here is that we must check if the superclass type
actually conforms to the requirement source's protocol, because it
is possible to have a superclass-constrained generic parameter
where some conformances are abstract. Eg, if SomeClass did not
conform to another protocol P2, we could write
In this case,
T : P2
is an abstract conformance on the typeT
.The common case where this would come up in real code is when you
have a class that conforms to a protocol with an associated type,
and one of the protocol requirements was fulfilled by a default in
a protocol extension, eg:
The above used to crash; now it will type-check correctly.
Fixes rdar://problem/44736411, https://bugs.swift.org/browse/SR-8814.