mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Sema] Don't suggest fixits that try to force unwrap implicit $match
Check if a variable is actually spelled out in code before suggesting a fixit that adds a force unwrap to it This fixes SR-1827
This commit is contained in:
@@ -2009,7 +2009,20 @@ commit_to_conversions:
|
||||
// If we have an optional type, try to force-unwrap it.
|
||||
// FIXME: Should we also try '?'?
|
||||
if (objectType1->getOptionalObjectType()) {
|
||||
conversionsOrFixes.push_back(FixKind::ForceOptional);
|
||||
bool forceUnwrapPossible = true;
|
||||
if (auto declRefExpr =
|
||||
dyn_cast_or_null<DeclRefExpr>(locator.trySimplifyToExpr())) {
|
||||
if (declRefExpr->getDecl()->isImplicit()) {
|
||||
// The expression that provides the first type is implicit and never
|
||||
// spelled out in source code, e.g. $match in an expression pattern.
|
||||
// Thus we cannot force unwrap the first type
|
||||
forceUnwrapPossible = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (forceUnwrapPossible) {
|
||||
conversionsOrFixes.push_back(FixKind::ForceOptional);
|
||||
}
|
||||
}
|
||||
|
||||
// If we have a value of type AnyObject that we're trying to convert to
|
||||
|
||||
Reference in New Issue
Block a user