Skip to content

Commit 998e620

Browse files
committed
Sema: Don't diagnose availability errors twice in non-single-expression closures
1 parent 6bb36b5 commit 998e620

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,6 +2267,10 @@ class AvailabilityWalker : public ASTWalker {
22672267
= TC.getFragileFunctionKind(DC);
22682268
}
22692269

2270+
bool shouldWalkIntoNonSingleExpressionClosure() override {
2271+
return false;
2272+
}
2273+
22702274
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
22712275
ExprStack.push_back(E);
22722276

test/attr/attr_availability_transitive_osx.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ var osx_extension_init_osx = osx() // expected-error {{'osx()' is unavailable}}
4949
@available(OSX, unavailable)
5050
var osx_inner_init_osx = { let inner_var = osx() } // OK
5151

52-
// FIXME: I'm not sure why this produces two errors instead of just one.
5352
@available(OSXApplicationExtension, unavailable)
54-
var osx_extension_inner_init_osx = { let inner_var = osx() } // expected-error 2 {{'osx()' is unavailable}}
53+
var osx_extension_inner_init_osx = { let inner_var = osx() } // expected-error {{'osx()' is unavailable}}
5554

5655
struct Outer {
5756
@available(OSX, unavailable)
@@ -93,9 +92,8 @@ struct Outer {
9392
@available(OSX, unavailable)
9493
var osx_inner_init_osx = { let inner_var = osx() } // OK
9594

96-
// FIXME: I'm not sure why this produces two errors instead of just one.
9795
@available(OSXApplicationExtension, unavailable)
98-
var osx_extension_inner_init_osx = { let inner_var = osx() } // expected-error 2 {{'osx()' is unavailable}}
96+
var osx_extension_inner_init_osx = { let inner_var = osx() } // expected-error {{'osx()' is unavailable}}
9997
}
10098

10199
extension Outer {

test/decl/func/default-values-swift4.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-testing
33

44
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}}
66
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}}
88
func internalFunction() {}
9-
// expected-note@-1 4{{global function 'internalFunction()' is not public}}
9+
// expected-note@-1 2{{global function 'internalFunction()' is not public}}
1010
@usableFromInline func versionedFunction() {}
11-
// expected-note@-1 7{{global function 'versionedFunction()' is not public}}
11+
// expected-note@-1 4{{global function 'versionedFunction()' is not public}}
1212
public func publicFunction() {}
1313

1414
func internalIntFunction() -> Int {}
1515
// expected-note@-1 {{global function 'internalIntFunction()' is not public}}
1616

1717
private func privateFunction2() {}
18-
// expected-note@-1 2{{global function 'privateFunction2()' is not '@usableFromInline' or public}}
18+
// expected-note@-1 {{global function 'privateFunction2()' is not '@usableFromInline' or public}}
1919
fileprivate func fileprivateFunction2() {}
20-
// expected-note@-1 2{{global function 'fileprivateFunction2()' is not '@usableFromInline' or public}}
20+
// expected-note@-1 {{global function 'fileprivateFunction2()' is not '@usableFromInline' or public}}
2121
func internalFunction2() {}
22-
// expected-note@-1 2{{global function 'internalFunction2()' is not '@usableFromInline' or public}}
22+
// expected-note@-1 {{global function 'internalFunction2()' is not '@usableFromInline' or public}}
2323

2424
func internalIntFunction2() -> Int {}
2525
// expected-note@-1 {{global function 'internalIntFunction2()' is not '@usableFromInline' or public}}
@@ -56,11 +56,11 @@ func internalFunctionWithDefaultValue(
5656
versionedFunction()
5757
// OK
5858
internalFunction2()
59-
// expected-error@-1 2{{global function 'internalFunction2()' is internal and cannot be referenced from a default argument value}}
59+
// expected-error@-1 {{global function 'internalFunction2()' is internal and cannot be referenced from a default argument value}}
6060
fileprivateFunction2()
61-
// expected-error@-1 2{{global function 'fileprivateFunction2()' is fileprivate and cannot be referenced from a default argument value}}
61+
// expected-error@-1 {{global function 'fileprivateFunction2()' is fileprivate and cannot be referenced from a default argument value}}
6262
privateFunction2()
63-
// expected-error@-1 2{{global function 'privateFunction2()' is private and cannot be referenced from a default argument value}}
63+
// expected-error@-1 {{global function 'privateFunction2()' is private and cannot be referenced from a default argument value}}
6464

6565
return 0
6666
}(),
@@ -77,16 +77,16 @@ public func publicFunctionWithDefaultValue(
7777
publicFunction()
7878

7979
versionedFunction()
80-
// expected-error@-1 2{{global function 'versionedFunction()' is internal and cannot be referenced from a default argument value}}
80+
// expected-error@-1 {{global function 'versionedFunction()' is internal and cannot be referenced from a default argument value}}
8181

8282
internalFunction()
83-
// expected-error@-1 2{{global function 'internalFunction()' is internal and cannot be referenced from a default argument value}}
83+
// expected-error@-1 {{global function 'internalFunction()' is internal and cannot be referenced from a default argument value}}
8484

8585
fileprivateFunction()
86-
// expected-error@-1 2{{global function 'fileprivateFunction()' is fileprivate and cannot be referenced from a default argument value}}
86+
// expected-error@-1 {{global function 'fileprivateFunction()' is fileprivate and cannot be referenced from a default argument value}}
8787

8888
privateFunction()
89-
// expected-error@-1 2{{global function 'privateFunction()' is private and cannot be referenced from a default argument value}}
89+
// expected-error@-1 {{global function 'privateFunction()' is private and cannot be referenced from a default argument value}}
9090

9191
return 0
9292
}(),
@@ -102,7 +102,7 @@ public func evilCode(
102102
x: Int = {
103103
let _ = publicFunction()
104104
let _ = versionedFunction()
105-
// expected-error@-1 2{{global function 'versionedFunction()' is internal and cannot be referenced from a default argument value}}
105+
// expected-error@-1 {{global function 'versionedFunction()' is internal and cannot be referenced from a default argument value}}
106106

107107
func localFunction() {
108108
publicFunction()
@@ -122,16 +122,16 @@ public struct HasSubscript {
122122
publicFunction()
123123

124124
versionedFunction()
125-
// expected-error@-1 2{{global function 'versionedFunction()' is internal and cannot be referenced from a default argument value}}
125+
// expected-error@-1 {{global function 'versionedFunction()' is internal and cannot be referenced from a default argument value}}
126126

127127
internalFunction()
128-
// expected-error@-1 2{{global function 'internalFunction()' is internal and cannot be referenced from a default argument value}}
128+
// expected-error@-1 {{global function 'internalFunction()' is internal and cannot be referenced from a default argument value}}
129129

130130
fileprivateFunction()
131-
// expected-error@-1 2{{global function 'fileprivateFunction()' is fileprivate and cannot be referenced from a default argument value}}
131+
// expected-error@-1 {{global function 'fileprivateFunction()' is fileprivate and cannot be referenced from a default argument value}}
132132

133133
privateFunction()
134-
// expected-error@-1 2{{global function 'privateFunction()' is private and cannot be referenced from a default argument value}}
134+
// expected-error@-1 {{global function 'privateFunction()' is private and cannot be referenced from a default argument value}}
135135

136136
return 0
137137
}()) -> Int {

0 commit comments

Comments
 (0)