Skip to content

Commit 0bcfd22

Browse files
committed
Sema: Clean up TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable()
1 parent 4769f21 commit 0bcfd22

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,31 +3399,20 @@ Type TypeChecker::checkReferenceOwnershipAttr(VarDecl *var, Type type,
33993399

34003400
Optional<Diag<>>
34013401
TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D) {
3402-
DeclContext *DC = D->getDeclContext();
3403-
// Do not permit potential availability of script-mode global variables;
3404-
// their initializer expression is not lazily evaluated, so this would
3405-
// not be safe.
3406-
if (isa<VarDecl>(D) && DC->isModuleScopeContext() &&
3407-
DC->getParentSourceFile()->isScriptMode()) {
3408-
return diag::availability_global_script_no_potential;
3409-
}
3410-
3411-
// For now, we don't allow stored properties to be potentially unavailable.
3412-
// We will want to support these eventually, but we haven't figured out how
3413-
// this will interact with Definite Initialization, deinitializers and
3414-
// resilience yet.
34153402
if (auto *VD = dyn_cast<VarDecl>(D)) {
3403+
if (!VD->hasStorage())
3404+
return None;
3405+
3406+
// Do not permit potential availability of script-mode global variables;
3407+
// their initializer expression is not lazily evaluated, so this would
3408+
// not be safe.
3409+
if (VD->isTopLevelGlobal())
3410+
return diag::availability_global_script_no_potential;
3411+
34163412
// Globals and statics are lazily initialized, so they are safe
3417-
// for potential unavailability. Note that if D is a global in script
3418-
// mode (which are not lazy) then we will already have returned
3419-
// a diagnosis above.
3420-
bool lazilyInitializedStored = VD->isStatic() ||
3421-
VD->getAttrs().hasAttribute<LazyAttr>() ||
3422-
DC->isModuleScopeContext();
3423-
3424-
if (VD->hasStorage() && !lazilyInitializedStored) {
3413+
// for potential unavailability.
3414+
if (!VD->isStatic() && !VD->getDeclContext()->isModuleScopeContext())
34253415
return diag::availability_stored_property_no_potential;
3426-
}
34273416
}
34283417

34293418
return None;

0 commit comments

Comments
 (0)