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

x/tools/gopls: Reports for redundant type conversion #58568

Open
pepehandsjpg opened this issue Feb 10, 2023 · 1 comment
Open

x/tools/gopls: Reports for redundant type conversion #58568

pepehandsjpg opened this issue Feb 10, 2023 · 1 comment
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@pepehandsjpg
Copy link

Problem
Sometimes you can miss redundant type conversion in your code.

var ids []int32
for _, groups := range groupsCollection {
    if len(groups) > 0 {
        ids = append(ids, int32(groups[0])) // groups[0] is already int32  so there is unnecessary conversion
    }
}

Solution
Could you add warnings about unnecessary type conversion as it is done in goland

@jamalc jamalc transferred this issue from golang/vscode-go Feb 16, 2023
@jamalc jamalc changed the title Reports for redundant type conversion x/tools/gopls: Reports for redundant type conversion Feb 16, 2023
@jamalc jamalc added this to the gopls/later milestone Feb 16, 2023
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Feb 16, 2023
@findleyr
Copy link
Contributor

See also dominikh/go-tools#936.

The concern expressed there remains: if gopls is only considering a single set of build tags, this analyzer may produce false positives.

I wonder how problematic those false positives would be. I also wonder how hard it would be to eliminate false positives by avoiding cases that could be affected by build tags.

CC @dominikh @mdempsky

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants