Skip to content

Commit 6677818

Browse files
committed
Added fixit to remove empty argument for non-function calls
1 parent ba21eb3 commit 6677818

File tree

8 files changed

+22
-11
lines changed

8 files changed

+22
-11
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4355,9 +4355,20 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
43554355
}
43564356
}
43574357

4358-
diagnose(callExpr->getArg()->getStartLoc(),
4359-
diag::cannot_call_non_function_value, fnExpr->getType())
4360-
.highlight(fnExpr->getSourceRange());
4358+
auto arg = callExpr->getArg();
4359+
auto diag = diagnose(arg->getStartLoc(),
4360+
diag::cannot_call_non_function_value,
4361+
fnExpr->getType());
4362+
diag.highlight(fnExpr->getSourceRange());
4363+
4364+
// If the argument is an empty tuple, then offer a
4365+
// fix-it to remove the empty tuple and use the value
4366+
// directly.
4367+
if (auto tuple = dyn_cast<TupleExpr>(arg)) {
4368+
if (tuple->getNumElements() == 0) {
4369+
diag.fixItRemove(arg->getSourceRange());
4370+
}
4371+
}
43614372
return true;
43624373
}
43634374

test/ClangModules/objc_parse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class NSObjectable : NSObjectProtocol {
305305
// Properties with custom accessors
306306
func customAccessors(_ hive: Hive, bee: Bee) {
307307
markUsed(hive.isMakingHoney)
308-
markUsed(hive.makingHoney()) // expected-error{{cannot call value of non-function type 'Bool'}}
308+
markUsed(hive.makingHoney()) // expected-error{{cannot call value of non-function type 'Bool'}}{{28-30=}}
309309
hive.setMakingHoney(true) // expected-error{{value of type 'Hive' has no member 'setMakingHoney'}}
310310

311311
_ = hive.`guard`.description // okay

test/Constraints/diagnostics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func rdar20142523() {
164164
// <rdar://problem/21080030> Bad diagnostic for invalid method call in boolean expression: (_, IntegerLiteralConvertible)' is not convertible to 'IntegerLiteralConvertible
165165
func rdar21080030() {
166166
var s = "Hello"
167-
if s.characters.count() == 0 {} // expected-error{{cannot call value of non-function type 'IndexDistance'}}
167+
if s.characters.count() == 0 {} // expected-error{{cannot call value of non-function type 'IndexDistance'}}{{24-26=}}
168168
}
169169

170170
// <rdar://problem/21248136> QoI: problem with return type inference mis-diagnosed as invalid arguments
@@ -290,7 +290,7 @@ _ = { $0 } // expected-error {{unable to infer closure return type in current c
290290

291291

292292

293-
_ = 4() // expected-error {{cannot call value of non-function type 'Int'}}
293+
_ = 4() // expected-error {{cannot call value of non-function type 'Int'}}{{6-8=}}
294294
_ = 4(1) // expected-error {{cannot call value of non-function type 'Int'}}
295295

296296

test/Constraints/fixes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func maybeFn() -> ((Int) -> Int)? { }
8787

8888
func extraCall() {
8989
var i = 7
90-
i = i() // expected-error{{cannot call value of non-function type 'Int'}}
90+
i = i() // expected-error{{cannot call value of non-function type 'Int'}}{{8-10=}}
9191

9292
maybeFn()(5) // expected-error{{value of optional type '((Int) -> Int)?' not unwrapped; did you mean to use '!' or '?'?}}{{12-12=!}}
9393
}

test/Sema/circular_decl_checking.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class HasGenericFunc {
2525

2626
class HasProp {
2727
var HasProp: HasProp {
28-
return HasProp() // expected-error {{cannot call value of non-function type 'HasProp'}}
28+
return HasProp() // expected-error {{cannot call value of non-function type 'HasProp'}}{{19-21=}}
2929
}
3030
var SomethingElse: SomethingElse? { // expected-error 2 {{use of undeclared type 'SomethingElse'}}
3131
return nil

test/expr/closure/closures.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func funcdecl5(_ a: Int, _ y: Int) {
5050
funcdecl1(123, 444)
5151

5252
// Calls.
53-
4() // expected-error {{cannot call value of non-function type 'Int'}}
53+
4() // expected-error {{cannot call value of non-function type 'Int'}}{{4-6=}}
5454

5555

5656
// rdar://12017658 - Infer some argument types from func6.

test/expr/expressions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func basictest() {
7676
var call3 : () = func3()()
7777

7878
// Cannot call an integer.
79-
bind_test2() // expected-error {{cannot call value of non-function type 'Int'}}
79+
bind_test2() // expected-error {{cannot call value of non-function type 'Int'}}{{13-15=}}
8080
}
8181

8282
// Infix operators and attribute lists.

test/expr/postfix/dot/init_ref_delegation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func foo<T: C where T: P>(_ x: T, y: T.Type) {
277277

278278
var ci1a = x(required: 0) // expected-error{{cannot call value of non-function type 'T'}}
279279
var ci2a = x(x: 0) // expected-error{{cannot call value of non-function type 'T'}}
280-
var ci3a = x() // expected-error{{cannot call value of non-function type 'T'}}
280+
var ci3a = x() // expected-error{{cannot call value of non-function type 'T'}}{{15-17=}}
281281
var ci4a = x(proto: "") // expected-error{{cannot call value of non-function type 'T'}}
282282

283283
var cm1 = y.init(required: 0)

0 commit comments

Comments
 (0)