Skip to content

Commit 740a319

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 061d92e commit 740a319

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-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+
WARNING(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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4324,6 +4324,13 @@ 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+
continue;
4332+
}
4333+
43274334
auto AtLoc = Attr->AtLoc;
43284335
auto Platform = Attr->Platform;
43294336

test/attr/attr_backDeployed.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,19 @@ 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+
@backDeployed(before: macOS 12.0) // expected-warning {{'@backDeployed' is unsupported on a var with a 'some' return type}}
269+
public var cannotBackDeployVarWithOpaqueResultType: some TopLevelProtocol {
270+
return ConformsToTopLevelProtocol()
271+
}
272+
273+
@backDeployed(before: macOS 12.0) // expected-warning {{'@backDeployed' is unsupported on a global function with a 'some' return type}}
274+
public func cannotBackDeployFuncWithOpaqueResultType() -> some TopLevelProtocol {
275+
return ConformsToTopLevelProtocol()
276+
}
264277

265278
// MARK: - Function body diagnostics
266279

0 commit comments

Comments
 (0)