2
2
// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-testing
3
3
4
4
private func privateFunction( ) { }
5
- // expected-note@-1 4 {{global function 'privateFunction()' is not public}}
5
+ // expected-note@-1 2 {{global function 'privateFunction()' is not public}}
6
6
fileprivate func fileprivateFunction( ) { }
7
- // expected-note@-1 4 {{global function 'fileprivateFunction()' is not public}}
7
+ // expected-note@-1 2 {{global function 'fileprivateFunction()' is not public}}
8
8
func internalFunction( ) { }
9
- // expected-note@-1 4 {{global function 'internalFunction()' is not public}}
9
+ // expected-note@-1 2 {{global function 'internalFunction()' is not public}}
10
10
@usableFromInline func versionedFunction( ) { }
11
+ // expected-note@-1 5{{global function 'versionedFunction()' is not public}}
11
12
public func publicFunction( ) { }
12
13
13
14
func internalIntFunction( ) -> Int { }
14
- // expected-note@-1 2{{global function 'internalIntFunction()' is not public}}
15
+ // expected-note@-1 {{global function 'internalIntFunction()' is not public}}
16
+
17
+ private func privateFunction2( ) { }
18
+ // expected-note@-1 2{{global function 'privateFunction2()' is not '@usableFromInline' or public}}
19
+ fileprivate func fileprivateFunction2( ) { }
20
+ // expected-note@-1 2{{global function 'fileprivateFunction2()' is not '@usableFromInline' or public}}
21
+ func internalFunction2( ) { }
22
+ // expected-note@-1 2{{global function 'internalFunction2()' is not '@usableFromInline' or public}}
23
+
24
+ func internalIntFunction2( ) -> Int { }
25
+ // expected-note@-1 {{global function 'internalIntFunction2()' is not '@usableFromInline' or public}}
15
26
16
27
func internalFunctionWithDefaultValue(
17
28
x: Int = {
@@ -44,17 +55,17 @@ func internalFunctionWithDefaultValue(
44
55
// OK
45
56
versionedFunction ( )
46
57
// 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}}
58
+ internalFunction2 ( )
59
+ // expected-error@-1 2{{global function 'internalFunction2 ()' is internal and cannot be referenced from a default argument value}}
60
+ fileprivateFunction2 ( )
61
+ // expected-error@-1 2{{global function 'fileprivateFunction2 ()' is fileprivate and cannot be referenced from a default argument value}}
62
+ privateFunction2 ( )
63
+ // expected-error@-1 2{{global function 'privateFunction2 ()' is private and cannot be referenced from a default argument value}}
53
64
54
65
return 0
55
66
} ( ) ,
56
- y: Int = internalIntFunction ( ) ) { }
57
- // expected-error@-1 {{global function 'internalIntFunction ()' is internal and cannot be referenced from a default argument value}}
67
+ y: Int = internalIntFunction2 ( ) ) { }
68
+ // expected-error@-1 {{global function 'internalIntFunction2 ()' is internal and cannot be referenced from a default argument value}}
58
69
59
70
public func publicFunctionWithDefaultValue(
60
71
x: Int = {
@@ -64,13 +75,16 @@ public func publicFunctionWithDefaultValue(
64
75
// FIXME: Some errors below are diagnosed twice
65
76
66
77
publicFunction ( )
67
- // OK
78
+
68
79
versionedFunction ( )
69
- // OK
80
+ // expected-error@-1 2{{global function 'versionedFunction()' is internal and cannot be referenced from a default argument value}}
81
+
70
82
internalFunction ( )
71
83
// expected-error@-1 2{{global function 'internalFunction()' is internal and cannot be referenced from a default argument value}}
84
+
72
85
fileprivateFunction ( )
73
86
// expected-error@-1 2{{global function 'fileprivateFunction()' is fileprivate and cannot be referenced from a default argument value}}
87
+
74
88
privateFunction ( )
75
89
// expected-error@-1 2{{global function 'privateFunction()' is private and cannot be referenced from a default argument value}}
76
90
@@ -83,3 +97,16 @@ public func publicFunctionWithDefaultValue(
83
97
public class MyClass {
84
98
public func method< T> ( _: T . Type = T . self) -> T { }
85
99
}
100
+
101
+ public func evilCode(
102
+ x: Int = {
103
+ let _ = publicFunction ( )
104
+ let _ = versionedFunction ( )
105
+ // expected-error@-1 2{{global function 'versionedFunction()' is internal and cannot be referenced from a default argument value}}
106
+
107
+ func localFunction( ) {
108
+ publicFunction ( )
109
+ versionedFunction ( )
110
+ // expected-error@-1 {{global function 'versionedFunction()' is internal and cannot be referenced from a default argument value}}
111
+ }
112
+ } ( ) ) { }
0 commit comments