Skip to content

Commit 6a43a68

Browse files
committed
Infer availability for typealiases for inferred type witness
Now that associated types can have availability, make sure that we infer availability attributes for any inferred type witnesses of said associated types based on both the enclosing context and the associated type itself. This eliminates failures in the emitted Swift interfaces. Fixes rdar://122596219.
1 parent f9e6478 commit 6a43a68

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/Sema/AssociatedTypeInference.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@ static void recordTypeWitness(NormalProtocolConformance *conformance,
298298
aliasDecl->getAttrs().add(attr);
299299
}
300300

301+
// Construct the availability of the type witnesses based on the
302+
// availability of the enclosing type and the associated type.
303+
const Decl * availabilitySources[2] = {dc->getAsDecl(), assocType };
304+
AvailabilityInference::applyInferredAvailableAttrs(
305+
aliasDecl, availabilitySources, ctx);
306+
301307
if (nominal == dc) {
302308
nominal->addMember(aliasDecl);
303309
} else {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name conformances
2+
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name conformances
3+
// RUN: %FileCheck %s < %t.swiftinterface
4+
5+
// REQUIRES: concurrency, OS=macosx
6+
7+
// CHECK: @available(
8+
// CHECK-NEXT: public struct SequenceAdapte
9+
@available(SwiftStdlib 5.1, *)
10+
public struct SequenceAdapter<Base: AsyncSequence>: AsyncSequence {
11+
// CHECK-LABEL: public struct AsyncIterator
12+
// CHECK: @available{{.*}}macOS 10.15
13+
// CHECK-NEXT: public typealias Element = Base.Element
14+
// CHECK: @available(
15+
// CHECK-NEXT: public typealias Failure = Base.Failure
16+
public typealias Element = Base.Element
17+
18+
public struct AsyncIterator: AsyncIteratorProtocol {
19+
public mutating func next() async rethrows -> Base.Element? { nil }
20+
}
21+
22+
// CHECK-LABEL: public func makeAsyncIterator
23+
public func makeAsyncIterator() -> AsyncIterator { AsyncIterator() }
24+
25+
// CHECK: @available(
26+
// CHECK-NEXT: public typealias Failure = Base.Failure
27+
}

0 commit comments

Comments
 (0)