Do not allow Any to satisfy more specific same-type constraints. (#3856)

For associated types inferred to be Any, we were allowing the type to
satisfy more specific same-type constraints, e.g. Element ==
Character (where Element is the associated type). This is clearly wrong.

The fix here is very specific to empty protocol compositions, and
removes some code in matchTypes() that doesn't make a lot of
sense. Looking back at the history, this was added in a commit that made
a handful of other changes, and it's not clear this particular change
was important for the issues that commit claimed to fix (and in fact
removing this regresses no tests).

Fixes rdar://problem/27515965.
This commit is contained in:
Mark Lacey
2016-07-29 12:38:07 -07:00
committed by Ted Kremenek
parent 8cb358195d
commit d470fc292e
2 changed files with 17 additions and 13 deletions

View File

@@ -1885,19 +1885,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, TypeMatchKind kind,
// we hit commit_to_conversions below, but we have to add a token restriction
// to ensure we wrap the metatype value in a metatype erasure.
if (concrete && type2->isExistentialType()) {
// If we're binding to an empty existential, we need to make sure that the
// conversion is valid.
if (kind == TypeMatchKind::BindType &&
type2->isEmptyExistentialComposition()) {
conversionsOrFixes.push_back(ConversionRestrictionKind::Existential);
addConstraint(ConstraintKind::SelfObjectOfProtocol,
type1, type2, getConstraintLocator(locator));
return SolutionKind::Solved;
}
if (kind == TypeMatchKind::ConformsTo) {
conversionsOrFixes.push_back(ConversionRestrictionKind::
MetatypeToExistentialMetatype);