Skip to content

Commit e03cf96

Browse files
committed
Sema: Diagnose invalid OS versions in if #available queries.
Part of rdar://155558161.
1 parent e3ab9a0 commit e03cf96

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5195,8 +5195,8 @@ static bool diagnoseAvailabilityCondition(PoundAvailableInfo *info,
51955195
return true;
51965196
}
51975197

5198+
auto rawVersion = parsedSpec->getRawVersion();
51985199
if (hasVersion) {
5199-
auto rawVersion = parsedSpec->getRawVersion();
52005200
if (!VersionRange::isValidVersion(rawVersion)) {
52015201
diags
52025202
.diagnose(loc, diag::availability_unsupported_version_number,
@@ -5211,6 +5211,12 @@ static bool diagnoseAvailabilityCondition(PoundAvailableInfo *info,
52115211
diags.diagnose(loc, diag::avail_query_expected_version_number);
52125212
return true;
52135213
}
5214+
5215+
if (!domain.isVersionValid(rawVersion)) {
5216+
diags.diagnose(loc,
5217+
diag::availability_invalid_version_number_for_domain,
5218+
rawVersion, domain);
5219+
}
52145220
} else if (hasVersion) {
52155221
diags.diagnose(loc, diag::availability_unexpected_version, domain)
52165222
.highlight(parsedSpec->getVersionSrcRange());

test/Availability/availability_versions_canonical.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ func useUnderPoundAvailable() {
9494
}
9595

9696
if #available(macOS 17.0, iOS 20.0, watchOS 13.0, tvOS 20.0, visionOS 4.0, *) {
97+
// expected-warning@-1 {{'17.0' is not a valid version number for macOS}}
98+
// expected-warning@-2 {{'20.0' is not a valid version number for iOS}}
99+
// expected-warning@-3 {{'13.0' is not a valid version number for watchOS}}
100+
// expected-warning@-4 {{'20.0' is not a valid version number for tvOS}}
101+
// expected-warning@-5 {{'4.0' is not a valid version number for visionOS}}
97102
introducedInVersionsMappingTo27_0()
98103
introducedIn27_0()
99104
}

0 commit comments

Comments
 (0)