Limit conversion that adds a global actor to a function type to subtyping.

Without this, we'll end up accepting invalid conversions when there
is a global actor-qualified function type in a non-top-level structural
position.
This commit is contained in:
Doug Gregor
2021-03-17 16:16:17 -07:00
parent 0f8e1cac4b
commit e50a944942
3 changed files with 26 additions and 0 deletions

View File

@@ -2025,11 +2025,16 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
return getTypeMatchFailure(locator);
} else if (func1->getGlobalActor()) {
// Cannot remove a global actor.
if (!shouldAttemptFixes())
return getTypeMatchFailure(locator);
auto *fix = MarkGlobalActorFunction::create(
*this, func1, func2, getConstraintLocator(locator));
if (recordFix(fix))
return getTypeMatchFailure(locator);
} else if (kind < ConstraintKind::Subtype) {
return getTypeMatchFailure(locator);
}
}