Skip to content

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

Merged
spytheman merged 5 commits into
vlang:masterfrom
ttytm:parser/unused-fn-params2
Nov 17, 2024
Merged

spytheman merged 5 commits into
vlang:masterfrom
ttytm:parser/unused-fn-params2

Conversation

@ttytm

@ttytm ttytm commented Nov 16, 2024 •

Copy link
Copy Markdown
Member

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

StunxFS commented Nov 16, 2024

Copy link
Copy Markdown
Contributor

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

ttytm commented Nov 16, 2024

Copy link
Copy Markdown
Member Author

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.

@ttytm
ttytm force-pushed the parser/unused-fn-params2 branch from 76a261c to 0f70595 Compare November 16, 2024 20:50
@StunxFS

StunxFS commented Nov 16, 2024

Copy link
Copy Markdown
Contributor

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.

Comment thread vlib/v/compiler_errors_test.v
@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
Copy Markdown
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

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

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
@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