Skip to content

Commit f0b4f4a

Browse files
committed
NCGenerics: omit inverses on invertible protocols
The interface files were still printing inverses on the invertible protocols, when that's not required. Doing so yielded warnings during the build because `~Escapable` isn't yet ready for appearing in the stdlib.
1 parent c67645f commit f0b4f4a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,9 +1581,16 @@ bestRequirementPrintLocation(ProtocolDecl *proto, const Requirement &req) {
15811581

15821582
void PrintAST::printInheritedFromRequirementSignature(ProtocolDecl *proto,
15831583
TypeDecl *attachingTo) {
1584+
unsigned flags = PrintInherited;
1585+
1586+
// The invertible protocols themselves do not need to state inverses in their
1587+
// inheritance clause, because they do not gain any default requirements.
1588+
if (!proto->getInvertibleProtocolKind())
1589+
flags |= PrintInverseRequirements;
1590+
15841591
printRequirementSignature(
15851592
proto, proto->getRequirementSignature(),
1586-
PrintInherited | PrintInverseRequirements,
1593+
flags,
15871594
attachingTo);
15881595
}
15891596

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-frontend %s \
2+
// RUN: -swift-version 5 \
3+
// RUN: -enable-library-evolution \
4+
// RUN: -emit-module -module-name Swift -parse-stdlib \
5+
// RUN: -enable-experimental-feature NoncopyableGenerics \
6+
// RUN: -o %t/Swift.swiftmodule \
7+
// RUN: -emit-module-interface-path %t/Swift.swiftinterface
8+
9+
// RUN: %FileCheck %s < %t/Swift.swiftinterface
10+
11+
// CHECK-DAG: @_marker public protocol Copyable {
12+
// CHECK-DAG: @_marker public protocol Escapable {
13+
14+
// This test verifies that:
15+
// 1. When omitted, the an invertible protocol decl gets automatically
16+
// synthesized into a module named Swift
17+
// 2. These protocol decls do not specify inverses in their inheritance clause
18+
// when emitted into the interface file.
19+
20+
@_marker public protocol Escapable { }

0 commit comments

Comments
 (0)