mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Transform EditorPlaceholderExpr into trap if executed in playground
mode (take 2)
Allow untyped placeholder to take arbitrary type, but default to Void.
Add _undefined<T>() function, which is like fatalError() but has
arbitrary return type. In playground mode, merely warn about outstanding
placeholders instead of erroring out, and transform placeholders into
calls to _undefined(). This way, code with outstanding placeholders will
only crash when it attempts to evaluate such placeholders.
When generating constraints for an iterated sequence of type T, emit
T convertible to $T1
$T1 conforms to SequenceType
instead of
T convertible to SequenceType
This ensures that an untyped placeholder in for-each sequence position
doesn't get inferred to have type SequenceType. (The conversion is still
necessary because the sequence may have IUO type.) The new constraint
system precipitates changes in CSSimplify and CSDiag, and ends up fixing
18741539 along the way.
(NOTE: There is a small regression in diagnosis of issues like the
following:
class C {}
class D: C {}
func f(a: [C]!) { for _: D in a {} }
It complains that [C]! doesn't conform to SequenceType when it should be
complaining that C is not convertible to D.)
<rdar://problem/21167372>
(Originally Swift SVN r31481)
This commit is contained in:
@@ -2290,12 +2290,30 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
|
||||
llvm_unreachable("bad constraint kind");
|
||||
}
|
||||
|
||||
if (!type->getAnyOptionalObjectType().isNull() &&
|
||||
protocol->isSpecificProtocol(KnownProtocolKind::BooleanType)) {
|
||||
Fixes.push_back({FixKind::OptionalToBoolean,
|
||||
getConstraintLocator(locator)});
|
||||
|
||||
return SolutionKind::Solved;
|
||||
if (!shouldAttemptFixes())
|
||||
return SolutionKind::Error;
|
||||
|
||||
// See if there's anything we can do to fix the conformance:
|
||||
OptionalTypeKind optionalKind;
|
||||
if (auto optionalObjectType = type->getAnyOptionalObjectType(optionalKind)) {
|
||||
if (protocol->isSpecificProtocol(KnownProtocolKind::BooleanType)) {
|
||||
// Optionals don't conform to BooleanType; suggest '!= nil'.
|
||||
if (recordFix(FixKind::OptionalToBoolean, getConstraintLocator(locator)))
|
||||
return SolutionKind::Error;
|
||||
return SolutionKind::Solved;
|
||||
} else if (optionalKind == OTK_Optional) {
|
||||
// The underlying type of an optional may conform to the protocol if the
|
||||
// optional doesn't; suggest forcing if that's the case.
|
||||
auto result = simplifyConformsToConstraint(
|
||||
optionalObjectType, protocol, kind,
|
||||
locator.withPathElement(LocatorPathElt::getGenericArgument(0)), flags);
|
||||
if (result == SolutionKind::Solved) {
|
||||
if (recordFix(FixKind::ForceOptional, getConstraintLocator(locator))) {
|
||||
return SolutionKind::Error;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// There's nothing more we can do; fail.
|
||||
|
||||
Reference in New Issue
Block a user