Skip to content

Commit afd1e7b

Browse files
committed
Update availability diagnostic for macOS major version number changes
Resolves: #57419
1 parent 3f76b8c commit afd1e7b

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

lib/Sema/TypeCheckAvailability.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1881,19 +1881,19 @@ static bool fixAvailabilityByNarrowingNearbyVersionCheck(
18811881
AvailabilityContext(RunningRange))) {
18821882

18831883
// Only fix situations that are "nearby" versions, meaning
1884-
// disagreement on a minor-or-less version for non-macOS,
1885-
// or disagreement on a subminor-or-less version for macOS.
1884+
// disagreement on a subminor-or-less version for macOS 10,
1885+
// or disagreement on a minor-or-less version otherwise.
18861886
auto RunningVers = RunningRange.getLowerEndpoint();
18871887
auto RequiredVers = RequiredRange.getLowerEndpoint();
18881888
auto Platform = targetPlatform(Context.LangOpts);
18891889
if (RunningVers.getMajor() != RequiredVers.getMajor())
18901890
return false;
18911891
if ((Platform == PlatformKind::macOS ||
18921892
Platform == PlatformKind::macOSApplicationExtension) &&
1893+
RunningVers.getMajor() == 10 &&
18931894
!(RunningVers.getMinor().has_value() &&
18941895
RequiredVers.getMinor().has_value() &&
1895-
RunningVers.getMinor().value() ==
1896-
RequiredVers.getMinor().value()))
1896+
RunningVers.getMinor().value() == RequiredVers.getMinor().value()))
18971897
return false;
18981898

18991899
auto FixRange = TRC->getAvailabilityConditionVersionSourceRange(

test/Sema/availability_versions_multi.swift

+6-10
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,16 @@ func useFromOtherOn99_51() {
3232

3333
let o10_9 = OtherIntroduced10_9()
3434
o10_9.extensionMethodOnOtherIntroduced10_9AvailableOn99_51(o99_51)
35-
_ = o99_51.returns99_52Introduced99_52() // expected-error {{'returns99_52Introduced99_52()' is only available in macOS 99.52 or newer}}
36-
// expected-note@-1 {{add 'if #available' version check}}
35+
_ = o99_51.returns99_52Introduced99_52() // expected-error {{'returns99_52Introduced99_52()' is only available in macOS 99.52 or newer}} {{26:29-34=99.52}}
3736

3837
_ = OtherIntroduced99_52()
39-
// expected-error@-1 {{'OtherIntroduced99_52' is only available in macOS 99.52 or newer}}
40-
// expected-note@-2 {{add 'if #available' version check}}
38+
// expected-error@-1 {{'OtherIntroduced99_52' is only available in macOS 99.52 or newer}} {{26:29-34=99.52}}
4139

42-
o99_51.extensionMethodOnOtherIntroduced99_51AvailableOn99_52() // expected-error {{'extensionMethodOnOtherIntroduced99_51AvailableOn99_52()' is only available in macOS 99.52 or newer}}
43-
// expected-note@-1 {{add 'if #available' version check}}
40+
o99_51.extensionMethodOnOtherIntroduced99_51AvailableOn99_52()
41+
// expected-error@-1 {{'extensionMethodOnOtherIntroduced99_51AvailableOn99_52()' is only available in macOS 99.52 or newer}} {{26:29-34=99.52}}
4442

4543
_ = OtherIntroduced99_51.NestedIntroduced99_52()
46-
// expected-error@-1 {{'NestedIntroduced99_52' is only available in macOS 99.52 or newer}}
47-
// expected-note@-2 {{add 'if #available' version check}}
44+
// expected-error@-1 {{'NestedIntroduced99_52' is only available in macOS 99.52 or newer}} {{26:29-34=99.52}}
4845
}
4946

5047
@available(OSX, introduced: 99.52)
@@ -53,8 +50,7 @@ func useFromOtherOn99_52() {
5350

5451
let n99_52 = OtherIntroduced99_51.NestedIntroduced99_52()
5552
_ = n99_52.returns99_52()
56-
_ = n99_52.returns99_53() // expected-error {{'returns99_53()' is only available in macOS 99.53 or newer}}
57-
// expected-note@-1 {{add 'if #available' version check}}
53+
_ = n99_52.returns99_53() // expected-error {{'returns99_53()' is only available in macOS 99.53 or newer}} {{47:29-34=99.53}}
5854

5955
// This will trigger validation of the global in availability_in_multi_other.swift
6056
_ = globalFromOtherOn99_52

0 commit comments

Comments
 (0)