Skip to content

Warning if a function call is missing parenthesis #58281

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

Closed
kinex opened this issue Dec 8, 2020 · 2 comments
Closed

Warning if a function call is missing parenthesis #58281

kinex opened this issue Dec 8, 2020 · 2 comments
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-lint-request type-enhancement A request for a change that isn't a bug

Comments

@kinex
Copy link

kinex commented Dec 8, 2020

I wrote by accident a function call without the parenthesis at the end. I even copy/pasted this code to several places before I noticed it in my final code review. I would have expected to get a warning about this.

Example:

void foo() {
}

void foo2(int i) {
}


void main() {
  foo; // Warning should be shown for this line for an invalid function call
  foo();
  foo2; // Also this should give a warning
}

I know that a function reference is needed in some situations (like when passing a function as a parameter), but in the example above the situation is clear (only a function call makes sense).

Dart SDK version: 2.10.4 (stable)

@kinex kinex added type-enhancement A request for a change that isn't a bug linter-lint-request labels Dec 8, 2020
@eernstg
Copy link
Member

eernstg commented Dec 8, 2020

foo; in main is a perfectly executable and type correct statement, but I would expect that some tool could report that it does not have any effect.

The action taken is: Create a function object (a first class function) corresponding to the function declaration named foo, and then discard it.

It's no worse than 1; which will evaluate the given expression to an object representing the integer 1 and then discard it.

You may prefer to enable https://dart-lang.github.io/linter/lints/unnecessary_statements.html. I don't know if that's detecting exactly the kinds of no-op statements that you're focusing on, but it does make the analyzer output a diagnostic message about the two lines foo; and foo2;.

@kinex
Copy link
Author

kinex commented Dec 8, 2020

I know those are correct statements, but clearly they are statements the developer did not write on purpose. And in my case it resulted a medium level bug (a required function call ChangeNotifier.notifylisteners() was omitted).

unnecessary_statements seems to help! Thanks. Little surprising that I have to enable this rule manually (even though I use also pedantic package). After enabling that rule I found also one new similar issue in my code base.

@kinex kinex closed this as completed Dec 8, 2020
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-lint-request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants