Skip to content

Commit 9796d1b

Browse files
authored
Merge pull request #78832 from tshortli/downgrade-more-available-than-enclosing-for-different-domain
Sema: Loosen the decl more available than enclosing diagnostic
2 parents 2f34f1d + 3b7ff19 commit 9796d1b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/Sema/TypeCheckAttr.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -2470,6 +2470,12 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *parsedAttr) {
24702470
// not diagnosed previously, so only emit a warning in that case.
24712471
if (isa<ExtensionDecl>(DC->getTopmostDeclarationDeclContext()))
24722472
limit = DiagnosticBehavior::Warning;
2473+
} else if (enclosingAttr.getPlatform() != attr->getPlatform()) {
2474+
// Downgrade to a warning when the limiting attribute is for a more
2475+
// specific platform.
2476+
if (inheritsAvailabilityFromPlatform(enclosingAttr.getPlatform(),
2477+
attr->getPlatform()))
2478+
limit = DiagnosticBehavior::Warning;
24732479
}
24742480
diagnose(D->isImplicit() ? enclosingDecl->getLoc()
24752481
: parsedAttr->getLocation(),

test/attr/attr_availability_maccatalyst.swift

+14
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,17 @@ public extension UnavailableOniOS { // ok
164164
public struct AvailableOnMacCatalyst { }
165165

166166
public extension AvailableOnMacCatalyst { } // ok
167+
168+
@available(iOS, introduced: 14.0)
169+
@available(macCatalyst, introduced: 14.5)
170+
public struct AvailableLaterOnMacCatalyst { // expected-note {{enclosing scope requires availability of Mac Catalyst 14.5 or newer}}
171+
@available(iOS, introduced: 14.0) // expected-warning {{instance method cannot be more available than enclosing scope}}
172+
func iOSOnly() { }
173+
174+
@available(macCatalyst, introduced: 14.5)
175+
func macCatalystOnly() { }
176+
177+
@available(iOS, introduced: 14.0)
178+
@available(macCatalyst, introduced: 14.5)
179+
func iOSAndMacCatalyst() { }
180+
}

0 commit comments

Comments
 (0)