Sema: Diagnose invalid OS versions in if #available queries.

Part of rdar://155558161.
This commit is contained in:
Allan Shortlidge
2025-07-10 14:33:28 -07:00
parent e3ab9a0e37
commit e03cf967c3
2 changed files with 12 additions and 1 deletions

View File

@@ -5195,8 +5195,8 @@ static bool diagnoseAvailabilityCondition(PoundAvailableInfo *info,
return true;
}
auto rawVersion = parsedSpec->getRawVersion();
if (hasVersion) {
auto rawVersion = parsedSpec->getRawVersion();
if (!VersionRange::isValidVersion(rawVersion)) {
diags
.diagnose(loc, diag::availability_unsupported_version_number,
@@ -5211,6 +5211,12 @@ static bool diagnoseAvailabilityCondition(PoundAvailableInfo *info,
diags.diagnose(loc, diag::avail_query_expected_version_number);
return true;
}
if (!domain.isVersionValid(rawVersion)) {
diags.diagnose(loc,
diag::availability_invalid_version_number_for_domain,
rawVersion, domain);
}
} else if (hasVersion) {
diags.diagnose(loc, diag::availability_unexpected_version, domain)
.highlight(parsedSpec->getVersionSrcRange());

View File

@@ -94,6 +94,11 @@ func useUnderPoundAvailable() {
}
if #available(macOS 17.0, iOS 20.0, watchOS 13.0, tvOS 20.0, visionOS 4.0, *) {
// expected-warning@-1 {{'17.0' is not a valid version number for macOS}}
// expected-warning@-2 {{'20.0' is not a valid version number for iOS}}
// expected-warning@-3 {{'13.0' is not a valid version number for watchOS}}
// expected-warning@-4 {{'20.0' is not a valid version number for tvOS}}
// expected-warning@-5 {{'4.0' is not a valid version number for visionOS}}
introducedInVersionsMappingTo27_0()
introducedIn27_0()
}