mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Make the "typechecked function body" request more central and resilient
The "typechecked function body" request was defined to type-check a function body that is known to be present, and not skipped, and would assert these conditions, requiring its users to check whether a body was expected. Often, this means that callers would use `getBody()` instead, which retrieves the underlying value in whatever form it happens to be, and assume it has been mutated appropriately. Make the "typechecked function body" request, triggered by `getTypecheckedBody()`, more resilient and central. A `NULL` result is now acceptable, signifying that there is no body. Clients will need to tolerate NULL results. * When there is no body but should be one, produce an appropriate error. * When there shouldn't be a body but is, produce an appropriate error * Handle skipping of function bodies here, rather than elsewhere. Over time, we should move clients off of `getBody` and `hasBody` entirely, and toward `getTypecheckedBody` or some yet-to-be-introduced forms like `getBodyAsWritten` for the pre-typechecked body.
This commit is contained in:
@@ -88,7 +88,7 @@ public:
|
||||
// Whitelist the kinds of decls to transform.
|
||||
// TODO: Expand the set of decls visited here.
|
||||
if (auto *FD = dyn_cast<AbstractFunctionDecl>(D))
|
||||
return Action::VisitChildrenIf(FD->getBody());
|
||||
return Action::VisitChildrenIf(FD->getTypecheckedBody());
|
||||
if (auto *TLCD = dyn_cast<TopLevelCodeDecl>(D))
|
||||
return Action::VisitChildrenIf(TLCD->getBody());
|
||||
if (isa<NominalTypeDecl>(D))
|
||||
|
||||
Reference in New Issue
Block a user