Skip to content
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

parser, checker, pref: allow getting notified about unused function params #22879

Merged
merged 5 commits into from
Nov 17, 2024

Conversation

ttytm
Copy link
Member

@ttytm ttytm commented Nov 16, 2024

The PR should implement #22875 as desired.

Example:

Screenshot_20241116_212257

NOTE: the v-analyzer hints won't work until this is on by default. For now, when compiling with -check-unused-fn-args you'll get:

fn (unused_receiver Foo) method(unused_param int) {}

fn func(unused_param int) {}
❯ v -check-unused-fn-args run vlib/v/checker/tests/unused_param.vv
vlib/v/checker/tests/unused_param.vv:5:33: notice: unused parameter: `unused_param`
    3 | struct Foo {}
    4 | 
    5 | fn (unused_receiver Foo) method(unused_param int) {}
      |                                 ~~~~~~~~~~~~
    6 | 
    7 | fn func(unused_param int) {}
vlib/v/checker/tests/unused_param.vv:7:9: notice: unused parameter: `unused_param`
    5 | fn (unused_receiver Foo) method(unused_param int) {}
    6 | 
    7 | fn func(unused_param int) {}
      |         ~~~~~~~~~~~~
    8 | 
    9 | pub fn pub_func(unused_param int) {}

Huly®: V_0.6-21322

@StunxFS
Copy link
Contributor

StunxFS commented Nov 16, 2024

It would be great if v fmt could detect unused parameters and use _ instead, thus automatically fixing all code with unused parameters.

Or, that there was a command, something like v fix, that could fix that problem automatically.

@ttytm
Copy link
Member Author

ttytm commented Nov 16, 2024

It would be great if v fmt could detect unused parameters and use _ instead, thus automatically fixing all code with unused parameters.

With this I see some situations where a format on save would replace the param name that is not in use yet but I want to use a few moments later.

@StunxFS
Copy link
Contributor

StunxFS commented Nov 16, 2024

It would be great if v fmt could detect unused parameters and use _ instead, thus automatically fixing all code with unused parameters.

With this I see some situations where a format on save would replace the param name that is not in use yet but I want to use a few moments later.

So it would be better to have a special command for automatic fixes: v fix, and when the compiler finds a problem that can be fixed using v fix, it would recommend using it.

@ttytm ttytm marked this pull request as ready for review November 16, 2024 20:58
@ttytm ttytm changed the title perser, checker, pref: allow getting notified about unused function params parser, checker, pref: allow getting notified about unused function params Nov 16, 2024
@medvednikov
Copy link
Member

So it would be better to have a special command for automatic fixes: v fix, and when the compiler finds a problem that can be fixed using v fix, it would recommend using it.

That's a great idea, I've always wanted something like that. Can fix mut params as well etc

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit ca236e9 into vlang:master Nov 17, 2024
72 checks passed
@ttytm ttytm deleted the parser/unused-fn-params2 branch November 17, 2024 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants