Skip to content

Commit 2f82acc

Browse files
authored
Merge pull request #10344 from slavapestov/underscored-attributes-are-secret
Sema: Don't talk about @_versioned in diagnostics for default arguments
2 parents 6607ff7 + 9b2b3b5 commit 2f82acc

File tree

4 files changed

+105
-74
lines changed

4 files changed

+105
-74
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3603,6 +3603,9 @@ ERROR(resilience_decl_unavailable,
36033603
#undef FRAGILE_FUNC_KIND
36043604

36053605
NOTE(resilience_decl_declared_here,
3606+
none, "%0 %1 is not public", (DescriptiveDeclKind, DeclName))
3607+
3608+
NOTE(resilience_decl_declared_here_versioned,
36063609
none, "%0 %1 is not '@_versioned' or public", (DescriptiveDeclKind, DeclName))
36073610

36083611
ERROR(designated_init_in_extension_resilient,none,

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,25 @@ bool TypeChecker::diagnoseInlineableDeclRef(SourceLoc loc,
113113
D->getDescriptiveKind(), D->getFullName(),
114114
D->getFormalAccessScope().accessibilityForDiagnostics(),
115115
getFragileFunctionKind(DC));
116-
diagnose(D, diag::resilience_decl_declared_here,
117-
D->getDescriptiveKind(), D->getFullName());
116+
117+
bool isDefaultArgument = false;
118+
while (DC->isLocalContext()) {
119+
if (isa<DefaultArgumentInitializer>(DC)) {
120+
isDefaultArgument = true;
121+
break;
122+
}
123+
124+
DC = DC->getParent();
125+
}
126+
127+
if (isDefaultArgument) {
128+
diagnose(D, diag::resilience_decl_declared_here,
129+
D->getDescriptiveKind(), D->getFullName());
130+
} else {
131+
diagnose(D, diag::resilience_decl_declared_here_versioned,
132+
D->getDescriptiveKind(), D->getFullName());
133+
}
134+
118135
return true;
119136
}
120137

test/attr/attr_inlineable.swift

Lines changed: 3 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
// expected-error@-1 {{@_inlineable cannot be applied to this declaration}}
66

77
private func privateFunction() {}
8-
// expected-note@-1 5{{global function 'privateFunction()' is not '@_versioned' or public}}
8+
// expected-note@-1{{global function 'privateFunction()' is not '@_versioned' or public}}
99
fileprivate func fileprivateFunction() {}
10-
// expected-note@-1 5{{global function 'fileprivateFunction()' is not '@_versioned' or public}}
10+
// expected-note@-1{{global function 'fileprivateFunction()' is not '@_versioned' or public}}
1111
func internalFunction() {}
12-
// expected-note@-1 5{{global function 'internalFunction()' is not '@_versioned' or public}}
12+
// expected-note@-1{{global function 'internalFunction()' is not '@_versioned' or public}}
1313
@_versioned func versionedFunction() {}
1414
public func publicFunction() {}
1515

16-
func internalIntFunction() -> Int {}
17-
// expected-note@-1 2{{global function 'internalIntFunction()' is not '@_versioned' or public}}
18-
1916
private struct PrivateStruct {}
2017
// expected-note@-1 3{{struct 'PrivateStruct' is not '@_versioned' or public}}
2118
struct InternalStruct {}
@@ -136,72 +133,6 @@ public struct Struct {
136133
}
137134
}
138135

139-
func internalFunctionWithDefaultValue(
140-
x: Int = {
141-
struct Nested {}
142-
// OK
143-
144-
publicFunction()
145-
// OK
146-
versionedFunction()
147-
// OK
148-
internalFunction()
149-
// OK
150-
fileprivateFunction()
151-
// OK
152-
privateFunction()
153-
// OK
154-
155-
return 0
156-
}(),
157-
y: Int = internalIntFunction()) {}
158-
159-
@_versioned func versionedFunctionWithDefaultValue(
160-
x: Int = {
161-
struct Nested {}
162-
// expected-error@-1 {{type 'Nested' cannot be nested inside a default argument value}}
163-
164-
// FIXME: Some errors below are diagnosed twice
165-
166-
publicFunction()
167-
// OK
168-
versionedFunction()
169-
// OK
170-
internalFunction()
171-
// expected-error@-1 2{{global function 'internalFunction()' is internal and cannot be referenced from a default argument value}}
172-
fileprivateFunction()
173-
// expected-error@-1 2{{global function 'fileprivateFunction()' is fileprivate and cannot be referenced from a default argument value}}
174-
privateFunction()
175-
// expected-error@-1 2{{global function 'privateFunction()' is private and cannot be referenced from a default argument value}}
176-
177-
return 0
178-
}(),
179-
y: Int = internalIntFunction()) {}
180-
// expected-error@-1 {{global function 'internalIntFunction()' is internal and cannot be referenced from a default argument value}}
181-
182-
public func publicFunctionWithDefaultValue(
183-
x: Int = {
184-
struct Nested {}
185-
// expected-error@-1 {{type 'Nested' cannot be nested inside a default argument value}}
186-
187-
// FIXME: Some errors below are diagnosed twice
188-
189-
publicFunction()
190-
// OK
191-
versionedFunction()
192-
// OK
193-
internalFunction()
194-
// expected-error@-1 2{{global function 'internalFunction()' is internal and cannot be referenced from a default argument value}}
195-
fileprivateFunction()
196-
// expected-error@-1 2{{global function 'fileprivateFunction()' is fileprivate and cannot be referenced from a default argument value}}
197-
privateFunction()
198-
// expected-error@-1 2{{global function 'privateFunction()' is private and cannot be referenced from a default argument value}}
199-
200-
return 0
201-
}(),
202-
y: Int = internalIntFunction()) {}
203-
// expected-error@-1 {{global function 'internalIntFunction()' is internal and cannot be referenced from a default argument value}}
204-
205136
// Make sure protocol extension members can reference protocol requirements
206137
// (which do not inherit the @_versioned attribute).
207138
@_versioned
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 4
2+
// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-testing
3+
4+
private func privateFunction() {}
5+
// expected-note@-1 4{{global function 'privateFunction()' is not public}}
6+
fileprivate func fileprivateFunction() {}
7+
// expected-note@-1 4{{global function 'fileprivateFunction()' is not public}}
8+
func internalFunction() {}
9+
// expected-note@-1 4{{global function 'internalFunction()' is not public}}
10+
@_versioned func versionedFunction() {}
11+
public func publicFunction() {}
12+
13+
func internalIntFunction() -> Int {}
14+
// expected-note@-1 2{{global function 'internalIntFunction()' is not public}}
15+
16+
func internalFunctionWithDefaultValue(
17+
x: Int = {
18+
struct Nested {}
19+
// OK
20+
21+
publicFunction()
22+
// OK
23+
versionedFunction()
24+
// OK
25+
internalFunction()
26+
// OK
27+
fileprivateFunction()
28+
// OK
29+
privateFunction()
30+
// OK
31+
32+
return 0
33+
}(),
34+
y: Int = internalIntFunction()) {}
35+
36+
@_versioned func versionedFunctionWithDefaultValue(
37+
x: Int = {
38+
struct Nested {}
39+
// expected-error@-1 {{type 'Nested' cannot be nested inside a default argument value}}
40+
41+
// FIXME: Some errors below are diagnosed twice
42+
43+
publicFunction()
44+
// OK
45+
versionedFunction()
46+
// OK
47+
internalFunction()
48+
// expected-error@-1 2{{global function 'internalFunction()' is internal and cannot be referenced from a default argument value}}
49+
fileprivateFunction()
50+
// expected-error@-1 2{{global function 'fileprivateFunction()' is fileprivate and cannot be referenced from a default argument value}}
51+
privateFunction()
52+
// expected-error@-1 2{{global function 'privateFunction()' is private and cannot be referenced from a default argument value}}
53+
54+
return 0
55+
}(),
56+
y: Int = internalIntFunction()) {}
57+
// expected-error@-1 {{global function 'internalIntFunction()' is internal and cannot be referenced from a default argument value}}
58+
59+
public func publicFunctionWithDefaultValue(
60+
x: Int = {
61+
struct Nested {}
62+
// expected-error@-1 {{type 'Nested' cannot be nested inside a default argument value}}
63+
64+
// FIXME: Some errors below are diagnosed twice
65+
66+
publicFunction()
67+
// OK
68+
versionedFunction()
69+
// OK
70+
internalFunction()
71+
// expected-error@-1 2{{global function 'internalFunction()' is internal and cannot be referenced from a default argument value}}
72+
fileprivateFunction()
73+
// expected-error@-1 2{{global function 'fileprivateFunction()' is fileprivate and cannot be referenced from a default argument value}}
74+
privateFunction()
75+
// expected-error@-1 2{{global function 'privateFunction()' is private and cannot be referenced from a default argument value}}
76+
77+
return 0
78+
}(),
79+
y: Int = internalIntFunction()) {}
80+
// expected-error@-1 {{global function 'internalIntFunction()' is internal and cannot be referenced from a default argument value}}

0 commit comments

Comments
 (0)