Sema: Diagnose invalid platform versions in @_originallyDefinedIn.

Part of rdar://155558161.
This commit is contained in:
Allan Shortlidge
2025-07-14 14:49:03 -07:00
parent 910989c2c2
commit 67d784fbaf
3 changed files with 16 additions and 4 deletions

View File

@@ -4916,14 +4916,21 @@ void AttributeChecker::checkOriginalDefinedInAttrs(
// Attrs are in the reverse order of the source order. We need to visit them
// in source order to diagnose the later attribute.
for (auto *Attr: Attrs) {
auto AtLoc = Attr->AtLoc;
auto Platform = Attr->getPlatform();
auto Domain = AvailabilityDomain::forPlatform(Platform);
auto ParsedVersion = Attr->getParsedMovedVersion();
if (!Domain.isVersionValid(ParsedVersion)) {
diagnose(AtLoc, diag::availability_invalid_version_number_for_domain,
ParsedVersion, Domain);
}
if (!Attr->isActivePlatform(Ctx))
continue;
if (diagnoseAndRemoveAttrIfDeclIsNonPublic(Attr, /*isError=*/false))
continue;
auto AtLoc = Attr->AtLoc;
auto Platform = Attr->getPlatform();
if (!seenPlatforms.insert({Platform, AtLoc}).second) {
// We've seen the platform before, emit error to the previous one which
// comes later in the source order.

View File

@@ -49,7 +49,7 @@ func testSpecialize<T>(arg: T) -> T {}
public func testBackDeployed() {}
@available(macOS 10, iOS 12, *)
@_originallyDefinedIn(module: "OriginalModule", macOS 12.0, iOS 23.2)
@_originallyDefinedIn(module: "OriginalModule", macOS 12.0, iOS 13.2)
public func testOriginallyDefinedIn() {}

View File

@@ -56,7 +56,12 @@ internal class ToplevelClass8 {}
public class ToplevelClass9 {}
@available(macOS 15, iOS 18, watchOS 11, tvOS 18, visionOS 2, *)
@_originallyDefinedIn(module: "foo", macOS 17, iOS 20, watchOS 13, tvOS 20, visionOS 4) // FIXME: Should be diagnosed
@_originallyDefinedIn(module: "foo", macOS 17, iOS 20, watchOS 13, tvOS 20, visionOS 4)
// expected-warning@-1 {{'17' is not a valid version number for macOS}}
// expected-warning@-2 {{'20' is not a valid version number for iOS}}
// expected-warning@-3 {{'13' is not a valid version number for watchOS}}
// expected-warning@-4 {{'20' is not a valid version number for tvOS}}
// expected-warning@-5 {{'4' is not a valid version number for visionOS}}
public class ToplevelClass10 {}
@available(macOS 15, iOS 18, watchOS 11, tvOS 18, visionOS 2, *)