Skip to content

Commit a9449e5

Browse files
committed
Sema: Diagnose @backDeployed on functions with opaque result types.
The compiler does not yet implement support for back deploying opaque result types. Resolves rdar://110806234
1 parent ee2fbb4 commit a9449e5

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6976,6 +6976,10 @@ ERROR(attr_incompatible_with_back_deploy,none,
69766976
"'%0' cannot be applied to a back deployed %1",
69776977
(DeclAttribute, DescriptiveDeclKind))
69786978

6979+
ERROR(backdeployed_opaque_result_not_supported,none,
6980+
"'%0' is unsupported on a %1 with a 'some' return type",
6981+
(DeclAttribute, DescriptiveDeclKind))
6982+
69796983
//------------------------------------------------------------------------------
69806984
// MARK: Implicit opening of existential types
69816985
//------------------------------------------------------------------------------

lib/Sema/TypeCheckAttr.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4324,6 +4324,14 @@ void AttributeChecker::checkBackDeployedAttrs(
43244324
}
43254325
}
43264326

4327+
if (VD->getOpaqueResultTypeDecl()) {
4328+
diagnoseAndRemoveAttr(Attr,
4329+
diag::backdeployed_opaque_result_not_supported,
4330+
Attr, D->getDescriptiveKind())
4331+
.warnInSwiftInterface(D->getDeclContext());
4332+
continue;
4333+
}
4334+
43274335
auto AtLoc = Attr->AtLoc;
43284336
auto Platform = Attr->Platform;
43294337

test/attr/attr_backDeployed.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,21 @@ protocol CannotBackDeployProtocol {}
261261
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' attribute cannot be applied to this declaration}}
262262
public actor CannotBackDeployActor {}
263263

264+
public struct ConformsToTopLevelProtocol: TopLevelProtocol {
265+
public init() {}
266+
}
267+
268+
@available(SwiftStdlib 5.1, *)
269+
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' is unsupported on a var with a 'some' return type}}
270+
public var cannotBackDeployVarWithOpaqueResultType: some TopLevelProtocol {
271+
return ConformsToTopLevelProtocol()
272+
}
273+
274+
@available(SwiftStdlib 5.1, *)
275+
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' is unsupported on a global function with a 'some' return type}}
276+
public func cannotBackDeployFuncWithOpaqueResultType() -> some TopLevelProtocol {
277+
return ConformsToTopLevelProtocol()
278+
}
264279

265280
// MARK: - Function body diagnostics
266281

0 commit comments

Comments
 (0)