Skip to content

Commit a250ab3

Browse files
committed
IDE: avoid merging extensions with @available attributes when synthesizing extensions
rdar://54804607
1 parent 1880eb0 commit a250ab3

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
@@ -179,7 +179,7 @@ struct SynthesizedExtensionAnalyzer::Implementation {
179179
}
180180
};
181181

182-
bool HasDocComment;
182+
bool Unmergable;
183183
unsigned InheritsCount;
184184
std::set<Requirement> Requirements;
185185
void addRequirement(GenericSignature *GenericSig,
@@ -194,14 +194,14 @@ struct SynthesizedExtensionAnalyzer::Implementation {
194194
}
195195
bool operator== (const ExtensionMergeInfo& Another) const {
196196
// Trivially unmergeable.
197-
if (HasDocComment || Another.HasDocComment)
197+
if (Unmergable || Another.Unmergable)
198198
return false;
199199
if (InheritsCount != 0 || Another.InheritsCount != 0)
200200
return false;
201201
return Requirements == Another.Requirements;
202202
}
203203
bool isMergeableWithTypeDef() {
204-
return !HasDocComment && InheritsCount == 0 && Requirements.empty();
204+
return !Unmergable && InheritsCount == 0 && Requirements.empty();
205205
}
206206
};
207207

@@ -279,7 +279,8 @@ struct SynthesizedExtensionAnalyzer::Implementation {
279279
ExtensionDecl *EnablingExt, NormalProtocolConformance *Conf) {
280280
SynthesizedExtensionInfo Result(IsSynthesized, EnablingExt);
281281
ExtensionMergeInfo MergeInfo;
282-
MergeInfo.HasDocComment = !Ext->getRawComment().isEmpty();
282+
MergeInfo.Unmergable = !Ext->getRawComment().isEmpty() || // With comments
283+
Ext->getAttrs().hasAttribute<AvailableAttr>(); // With @available
283284
MergeInfo.InheritsCount = countInherits(Ext);
284285

285286
// 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)