@@ -3399,31 +3399,20 @@ Type TypeChecker::checkReferenceOwnershipAttr(VarDecl *var, Type type,
3399
3399
3400
3400
Optional<Diag<>>
3401
3401
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.
3415
3402
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
+
3416
3412
// 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 ())
3425
3415
return diag::availability_stored_property_no_potential;
3426
- }
3427
3416
}
3428
3417
3429
3418
return None;
0 commit comments