Skip to content

Commit 67d784f

Browse files
committed
Sema: Diagnose invalid platform versions in @_originallyDefinedIn.
Part of rdar://155558161.
1 parent 910989c commit 67d784f

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4916,14 +4916,21 @@ void AttributeChecker::checkOriginalDefinedInAttrs(
49164916
// Attrs are in the reverse order of the source order. We need to visit them
49174917
// in source order to diagnose the later attribute.
49184918
for (auto *Attr: Attrs) {
4919+
auto AtLoc = Attr->AtLoc;
4920+
auto Platform = Attr->getPlatform();
4921+
auto Domain = AvailabilityDomain::forPlatform(Platform);
4922+
auto ParsedVersion = Attr->getParsedMovedVersion();
4923+
if (!Domain.isVersionValid(ParsedVersion)) {
4924+
diagnose(AtLoc, diag::availability_invalid_version_number_for_domain,
4925+
ParsedVersion, Domain);
4926+
}
4927+
49194928
if (!Attr->isActivePlatform(Ctx))
49204929
continue;
49214930

49224931
if (diagnoseAndRemoveAttrIfDeclIsNonPublic(Attr, /*isError=*/false))
49234932
continue;
49244933

4925-
auto AtLoc = Attr->AtLoc;
4926-
auto Platform = Attr->getPlatform();
49274934
if (!seenPlatforms.insert({Platform, AtLoc}).second) {
49284935
// We've seen the platform before, emit error to the previous one which
49294936
// comes later in the source order.

test/ASTGen/availability.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func testSpecialize<T>(arg: T) -> T {}
4949
public func testBackDeployed() {}
5050

5151
@available(macOS 10, iOS 12, *)
52-
@_originallyDefinedIn(module: "OriginalModule", macOS 12.0, iOS 23.2)
52+
@_originallyDefinedIn(module: "OriginalModule", macOS 12.0, iOS 13.2)
5353
public func testOriginallyDefinedIn() {}
5454

5555

test/Parse/original_defined_in_attr.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ internal class ToplevelClass8 {}
5656
public class ToplevelClass9 {}
5757

5858
@available(macOS 15, iOS 18, watchOS 11, tvOS 18, visionOS 2, *)
59-
@_originallyDefinedIn(module: "foo", macOS 17, iOS 20, watchOS 13, tvOS 20, visionOS 4) // FIXME: Should be diagnosed
59+
@_originallyDefinedIn(module: "foo", macOS 17, iOS 20, watchOS 13, tvOS 20, visionOS 4)
60+
// expected-warning@-1 {{'17' is not a valid version number for macOS}}
61+
// expected-warning@-2 {{'20' is not a valid version number for iOS}}
62+
// expected-warning@-3 {{'13' is not a valid version number for watchOS}}
63+
// expected-warning@-4 {{'20' is not a valid version number for tvOS}}
64+
// expected-warning@-5 {{'4' is not a valid version number for visionOS}}
6065
public class ToplevelClass10 {}
6166

6267
@available(macOS 15, iOS 18, watchOS 11, tvOS 18, visionOS 2, *)

0 commit comments

Comments
 (0)