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

staticcheck: replace reflect.Value.MethodByName with type assertion #1348

Open
dominikh opened this issue Jan 3, 2023 · 0 comments
Open
Labels
needs-decision We have to decide if this check is feasible and desirable new-check

Comments

@dominikh
Copy link
Owner

dominikh commented Jan 3, 2023

When MethodByName is used with a static string, we can instead use Interface and a type assertion. This has the benefit of not disabling the linker's dead code elimination.

Tagged needs-decision because there's the potential for this to be noisy. There are various reasons why the user might not care, maybe they're already importing another library that uses MethodByName.

Via mvdan, via google/starlark-go#444

@dominikh dominikh added needs-decision We have to decide if this check is feasible and desirable new-check labels Jan 3, 2023
mvdan added a commit to mvdan/sh that referenced this issue Jan 3, 2023
We only used it with static method names,
so we can use type assertions to reach those methods instead.
This is easier as we avoid more reflection,
and does not throw off the linker's dead code elimination.

See dominikh/go-tools#1348.
mvdan added a commit to mvdan/sh that referenced this issue Jan 7, 2023
We only used it with static method names,
so we can use type assertions to reach those methods instead.
This is easier as we avoid more reflection,
and does not throw off the linker's dead code elimination.

See dominikh/go-tools#1348.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision We have to decide if this check is feasible and desirable new-check
Projects
None yet
Development

No branches or pull requests

1 participant