Skip to content

Commit cdf4bc3

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 a971a0c commit cdf4bc3

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

include/swift/AST/DiagnosticsSema.def

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

7056+
ERROR(backdeployed_opaque_result_not_supported,none,
7057+
"'%0' is unsupported on a %1 with a 'some' return type",
7058+
(DeclAttribute, DescriptiveDeclKind))
7059+
70567060
//------------------------------------------------------------------------------
70577061
// MARK: Implicit opening of existential types
70587062
//------------------------------------------------------------------------------

lib/Sema/TypeCheckAttr.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4349,6 +4349,14 @@ void AttributeChecker::checkBackDeployedAttrs(
43494349
}
43504350
}
43514351

4352+
if (VD->getOpaqueResultTypeDecl()) {
4353+
diagnoseAndRemoveAttr(Attr,
4354+
diag::backdeployed_opaque_result_not_supported,
4355+
Attr, D->getDescriptiveKind())
4356+
.warnInSwiftInterface(D->getDeclContext());
4357+
continue;
4358+
}
4359+
43524360
auto AtLoc = Attr->AtLoc;
43534361
auto Platform = Attr->Platform;
43544362

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-error {{'@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-error {{'@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)