Skip to content

use-fmt-print: skip locally shadowed print and println - #1945

Open
HawkForge wants to merge 1 commit into
revive-lint:masterfrom
HawkForge:fix/use-fmt-print-local-shadowing
Open

HawkForge wants to merge 1 commit into
revive-lint:masterfrom
HawkForge:fix/use-fmt-print-local-shadowing

Conversation

@HawkForge

Copy link
Copy Markdown

Fixes #1874. Thanks to @dajiaohuang for the report.

The rule only treated print/println as user-defined when the file had a top-level function with that name, so calls through a parameter, a local variable or a named result were reported as the built-in.

The visitor now skips a callee identifier whose Obj is set, i.e. one the parser resolved to a declaration in scope; only an unresolved identifier can be the built-in. I kept the rule untyped (it is listed in untyped.toml) and used Ident.Obj as other rules here already do, rather than requiring type information.

testdata/use_fmt_print_with_local_shadowing.go covers a parameter, a local variable and a named result (no failure) and real built-in calls (reported). It fails without the fix.

A print/println function declared at package level in another file of the package is still not detected; that would need type information.


Replaces #1923, which got closed when my fork was accidentally detached.

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.

1 participant