Skip to content

Commit ef7185a

Browse files
committed
Don't infer empty availability attributes
Due to the mapping of iOS platform availability to tvOS platform availability, we were ending up inferring an availability attribute `@available(tvOS)` for an associated type, which does not parse properly. Suppress the creation of inferred availability attributes when they convey no information (e.g., because they have no introduced/deprecated/obsoleted/etc. in them). Fixes rdar://123545422.
1 parent 1c652ef commit ef7185a

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

lib/AST/Availability.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ static AvailableAttr *createAvailableAttr(PlatformKind Platform,
109109
StringRef Rename,
110110
ValueDecl *RenameDecl,
111111
ASTContext &Context) {
112+
// If there is no information that would go into the availability attribute,
113+
// don't create one.
114+
if (!Inferred.Introduced && !Inferred.Deprecated && !Inferred.Obsoleted &&
115+
Message.empty() && Rename.empty() && !RenameDecl)
116+
return nullptr;
117+
112118
llvm::VersionTuple Introduced =
113119
Inferred.Introduced.value_or(llvm::VersionTuple());
114120
llvm::VersionTuple Deprecated =
@@ -189,7 +195,8 @@ void AvailabilityInference::applyInferredAvailableAttrs(
189195
auto *Attr = createAvailableAttr(Pair.first, Pair.second, Message,
190196
Rename, RenameDecl, Context);
191197

192-
Attrs.add(Attr);
198+
if (Attr)
199+
Attrs.add(Attr);
193200
}
194201
}
195202

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__attribute__((availability(ios,introduced=2.0)))
2+
@interface TheColor
3+
@end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module CAssoc {
2+
header "assoc.h"
3+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// FIXME: BEGIN -enable-source-import hackaround
4+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -emit-module -o %t %clang-importer-sdk-path/swift-modules/CoreGraphics.swift
5+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -emit-module -o %t %clang-importer-sdk-path/swift-modules/Foundation.swift
6+
// FIXME: END -enable-source-import hackaround
7+
8+
// RUN: %target-swift-emit-module-interface(%t/assoc_type_inference_tvos.swiftinterface) %s %clang-importer-sdk -F %clang-importer-sdk-path/frameworks -I %S/Inputs/assoc_type_inference_tvos
9+
// RUN: %FileCheck --input-file %t/assoc_type_inference_tvos.swiftinterface %s
10+
// RUN: %target-swift-typecheck-module-from-interface(%t/assoc_type_inference_tvos.swiftinterface) %clang-importer-sdk -F %clang-importer-sdk-path/frameworks -I %S/Inputs/assoc_type_inference_tvos
11+
12+
// REQUIRES: objc_interop
13+
14+
import CAssoc
15+
16+
extension TheColor {
17+
// This checks for the absence of an @available(tvOS) on an associated type
18+
// that is inferred to have tvOS availability based on its enclosing type
19+
// having iOS availability that predates the introduction of tvOS.
20+
21+
// CHECK: public init?(rawValue: Swift.String)
22+
// CHECK-NOT: @available(tvOS
23+
// CHECK: public typealias RawValue = Swift.String
24+
public enum StaticNamedColor: String {
25+
case black
26+
}
27+
}

0 commit comments

Comments
 (0)