From 6a43a680d1a0e36140eac5bea93ce7aab1026e30 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Thu, 8 Feb 2024 19:10:54 -0800 Subject: [PATCH] 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. --- lib/Sema/AssociatedTypeInference.cpp | 6 +++++ .../async_sequence_conformance.swift | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/ModuleInterface/async_sequence_conformance.swift diff --git a/lib/Sema/AssociatedTypeInference.cpp b/lib/Sema/AssociatedTypeInference.cpp index 969a7b1136ea2..58e0bad68d356 100644 --- a/lib/Sema/AssociatedTypeInference.cpp +++ b/lib/Sema/AssociatedTypeInference.cpp @@ -298,6 +298,12 @@ static void recordTypeWitness(NormalProtocolConformance *conformance, aliasDecl->getAttrs().add(attr); } + // Construct the availability of the type witnesses based on the + // availability of the enclosing type and the associated type. + const Decl * availabilitySources[2] = {dc->getAsDecl(), assocType }; + AvailabilityInference::applyInferredAvailableAttrs( + aliasDecl, availabilitySources, ctx); + if (nominal == dc) { nominal->addMember(aliasDecl); } else { diff --git a/test/ModuleInterface/async_sequence_conformance.swift b/test/ModuleInterface/async_sequence_conformance.swift new file mode 100644 index 0000000000000..8de164de830f8 --- /dev/null +++ b/test/ModuleInterface/async_sequence_conformance.swift @@ -0,0 +1,27 @@ +// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name conformances +// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name conformances +// RUN: %FileCheck %s < %t.swiftinterface + +// REQUIRES: concurrency, OS=macosx + +// CHECK: @available( +// CHECK-NEXT: public struct SequenceAdapte +@available(SwiftStdlib 5.1, *) +public struct SequenceAdapter: AsyncSequence { + // CHECK-LABEL: public struct AsyncIterator + // CHECK: @available{{.*}}macOS 10.15 + // CHECK-NEXT: public typealias Element = Base.Element + // CHECK: @available( + // CHECK-NEXT: public typealias Failure = Base.Failure + public typealias Element = Base.Element + + public struct AsyncIterator: AsyncIteratorProtocol { + public mutating func next() async rethrows -> Base.Element? { nil } + } + + // CHECK-LABEL: public func makeAsyncIterator + public func makeAsyncIterator() -> AsyncIterator { AsyncIterator() } + + // CHECK: @available( + // CHECK-NEXT: public typealias Failure = Base.Failure +}