Skip to content

Commit c2cce35

Browse files
committed
IDE: avoid merging extensions with @available attributes when synthesizing extensions
rdar://54804607
1 parent 07bcf5a commit c2cce35

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/IDE/IDETypeChecking.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ struct SynthesizedExtensionAnalyzer::Implementation {
181181
}
182182
};
183183

184-
bool HasDocComment;
184+
bool Unmergable;
185185
unsigned InheritsCount;
186186
std::set<Requirement> Requirements;
187187
void addRequirement(GenericSignature *GenericSig,
@@ -196,14 +196,14 @@ struct SynthesizedExtensionAnalyzer::Implementation {
196196
}
197197
bool operator== (const ExtensionMergeInfo& Another) const {
198198
// Trivially unmergeable.
199-
if (HasDocComment || Another.HasDocComment)
199+
if (Unmergable || Another.Unmergable)
200200
return false;
201201
if (InheritsCount != 0 || Another.InheritsCount != 0)
202202
return false;
203203
return Requirements == Another.Requirements;
204204
}
205205
bool isMergeableWithTypeDef() {
206-
return !HasDocComment && InheritsCount == 0 && Requirements.empty();
206+
return !Unmergable && InheritsCount == 0 && Requirements.empty();
207207
}
208208
};
209209

@@ -281,7 +281,8 @@ struct SynthesizedExtensionAnalyzer::Implementation {
281281
ExtensionDecl *EnablingExt, NormalProtocolConformance *Conf) {
282282
SynthesizedExtensionInfo Result(IsSynthesized, EnablingExt);
283283
ExtensionMergeInfo MergeInfo;
284-
MergeInfo.HasDocComment = !Ext->getRawComment().isEmpty();
284+
MergeInfo.Unmergable = !Ext->getRawComment().isEmpty() || // With comments
285+
Ext->getAttrs().hasAttribute<AvailableAttr>(); // With @available
285286
MergeInfo.InheritsCount = countInherits(Ext);
286287

287288
// There's (up to) two extensions here: the extension with the items that we
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module-path %t/print_synthesized_extensions_nomerge.swiftmodule -emit-module-doc -emit-module-doc-path %t/print_synthesized_extensions.swiftdoc %s
3+
// RUN: %target-swift-ide-test -print-module -annotate-print -synthesize-extension -print-interface -no-empty-line-between-members -module-to-print=print_synthesized_extensions_nomerge -I %t -source-filename=%s > %t.syn.txt
4+
// RUN: %FileCheck %s -check-prefix=CHECK1 < %t.syn.txt
5+
6+
public struct S1 {}
7+
8+
@available(macOS 10.15, *)
9+
public extension S1 {
10+
func foo() {}
11+
}
12+
13+
@available(iOS 13, *)
14+
public extension S1 {
15+
func bar() {}
16+
}
17+
18+
// CHECK1: <decl:Extension>@available(OSX 10.15, *)
19+
// CHECK1: extension <loc><ref:Struct>S1</ref></loc> {
20+
// CHECK1: <decl:Extension>@available(iOS 13, *)
21+
// CHECK1: extension <loc><ref:Struct>S1</ref></loc> {

0 commit comments

Comments
 (0)