@@ -237,38 +237,35 @@ struct RuntimeVersionCheck {
237237// / information about the runtime check needed to ensure it is available to
238238// / \c versionCheck and returns true.
239239static bool
240- checkAvailability (const EnumElementDecl *elt, ASTContext &C,
240+ checkAvailability (const EnumElementDecl *elt, DeclContext *dc,
241+ AvailabilityContext availabilityContext,
241242 std::optional<RuntimeVersionCheck> &versionCheck) {
242- auto *attr = elt->getAttrs ().getPotentiallyUnavailable (C);
243+ auto &C = dc->getASTContext ();
244+ auto constraint =
245+ getUnsatisfiedAvailabilityConstraint (elt, dc, availabilityContext);
243246
244247 // Is it always available?
245- if (!attr )
248+ if (!constraint )
246249 return true ;
247250
248- // For type-checking purposes, iOS availability is inherited for visionOS
249- // targets. However, it is not inherited for the sake of code-generation
250- // of runtime availability queries, and is assumed to be available.
251- if ((attr->Platform == PlatformKind::iOS ||
252- attr->Platform == PlatformKind::iOSApplicationExtension) &&
253- C.LangOpts .Target .isXROS ())
251+ // Some constraints are active for type checking but can't translate to
252+ // runtime restrictions.
253+ if (!constraint->isActiveForRuntimeQueries (C))
254254 return true ;
255255
256- AvailableVersionComparison availability = attr->getVersionAvailability (C);
257-
258- assert (availability != AvailableVersionComparison::Available &&
259- " DeclAttributes::getPotentiallyUnavailable() shouldn't "
260- " return an available attribute" );
261-
262256 // Is it never available?
263- if (availability != AvailableVersionComparison::PotentiallyUnavailable )
257+ if (!constraint-> isConditionallySatisfiable () )
264258 return false ;
265259
266260 // It's conditionally available; create a version constraint and return true.
267- assert (attr->getPlatformAgnosticAvailability () ==
268- PlatformAgnosticAvailabilityKind::None &&
269- " can only express #available(somePlatform version) checks" );
270- versionCheck.emplace (attr->Platform , *attr->Introduced );
261+ auto platform = constraint->getPlatform ();
262+ auto range = constraint->getRequiredNewerAvailabilityRange (C);
263+
264+ // Only platform version constraints are supported currently.
265+ ASSERT (platform != PlatformKind::none);
266+ ASSERT (range);
271267
268+ versionCheck.emplace (platform, range->getRawMinimumVersion ());
272269 return true ;
273270}
274271
@@ -295,6 +292,7 @@ deriveBodyRawRepresentable_init(AbstractFunctionDecl *initDecl, void *) {
295292
296293 auto parentDC = initDecl->getDeclContext ();
297294 ASTContext &C = parentDC->getASTContext ();
295+ auto availabilityContext = AvailabilityContext::forDeploymentTarget (C);
298296
299297 auto nominalTypeDecl = parentDC->getSelfNominalTypeDecl ();
300298 auto enumDecl = cast<EnumDecl>(nominalTypeDecl);
@@ -318,7 +316,7 @@ deriveBodyRawRepresentable_init(AbstractFunctionDecl *initDecl, void *) {
318316 // information about that check in versionCheck and keep processing this
319317 // element.
320318 std::optional<RuntimeVersionCheck> versionCheck (std::nullopt );
321- if (!checkAvailability (elt, C , versionCheck))
319+ if (!checkAvailability (elt, parentDC, availabilityContext , versionCheck))
322320 continue ;
323321
324322 // litPat = elt.rawValueExpr as a pattern
0 commit comments