Skip to content

Fixit to remove empty argument for non-function calls #3196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4355,9 +4355,20 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
}
}

diagnose(callExpr->getArg()->getStartLoc(),
diag::cannot_call_non_function_value, fnExpr->getType())
.highlight(fnExpr->getSourceRange());
auto arg = callExpr->getArg();
auto diag = diagnose(arg->getStartLoc(),
diag::cannot_call_non_function_value,
fnExpr->getType());
diag.highlight(fnExpr->getSourceRange());

// If the argument is an empty tuple, then offer a
// fix-it to remove the empty tuple and use the value
// directly.
if (auto tuple = dyn_cast<TupleExpr>(arg)) {
if (tuple->getNumElements() == 0) {
diag.fixItRemove(arg->getSourceRange());
}
}
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion test/ClangModules/objc_parse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class NSObjectable : NSObjectProtocol {
// Properties with custom accessors
func customAccessors(_ hive: Hive, bee: Bee) {
markUsed(hive.isMakingHoney)
markUsed(hive.makingHoney()) // expected-error{{cannot call value of non-function type 'Bool'}}
markUsed(hive.makingHoney()) // expected-error{{cannot call value of non-function type 'Bool'}}{{28-30=}}
hive.setMakingHoney(true) // expected-error{{value of type 'Hive' has no member 'setMakingHoney'}}

_ = hive.`guard`.description // okay
Expand Down
4 changes: 2 additions & 2 deletions test/Constraints/diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func rdar20142523() {
// <rdar://problem/21080030> Bad diagnostic for invalid method call in boolean expression: (_, IntegerLiteralConvertible)' is not convertible to 'IntegerLiteralConvertible
func rdar21080030() {
var s = "Hello"
if s.characters.count() == 0 {} // expected-error{{cannot call value of non-function type 'IndexDistance'}}
if s.characters.count() == 0 {} // expected-error{{cannot call value of non-function type 'IndexDistance'}}{{24-26=}}
}

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



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


Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/fixes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func maybeFn() -> ((Int) -> Int)? { }

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

maybeFn()(5) // expected-error{{value of optional type '((Int) -> Int)?' not unwrapped; did you mean to use '!' or '?'?}}{{12-12=!}}
}
Expand Down
2 changes: 1 addition & 1 deletion test/Sema/circular_decl_checking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class HasGenericFunc {

class HasProp {
var HasProp: HasProp {
return HasProp() // expected-error {{cannot call value of non-function type 'HasProp'}}
return HasProp() // expected-error {{cannot call value of non-function type 'HasProp'}}{{19-21=}}
}
var SomethingElse: SomethingElse? { // expected-error 2 {{use of undeclared type 'SomethingElse'}}
return nil
Expand Down
2 changes: 1 addition & 1 deletion test/expr/closure/closures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func funcdecl5(_ a: Int, _ y: Int) {
funcdecl1(123, 444)

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


// rdar://12017658 - Infer some argument types from func6.
Expand Down
2 changes: 1 addition & 1 deletion test/expr/expressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func basictest() {
var call3 : () = func3()()

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

// Infix operators and attribute lists.
Expand Down
2 changes: 1 addition & 1 deletion test/expr/postfix/dot/init_ref_delegation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func foo<T: C where T: P>(_ x: T, y: T.Type) {

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

var cm1 = y.init(required: 0)
Expand Down