Skip to content

cmd/vet: incorrect "redundant invocation" report #6148

@fsouza

Description

@fsouza
% cat abc.go
package main

import (
    "fmt"
)

type Person struct {
    name string
}

func (p *Person) String() string {
    return p.name
}

func main() {
    p := Person{name: "Gopher"}
    fmt.Printf("%s\n", p.String())
}
% go vet abc.go
abc.go:17: redundant invocation of String method of p

It's not redundant, because String method requires a pointer receiver. So, *Person
implements the Stringer interface, but Person does not.

Following vet advice produces the wrong result: http://play.golang.org/p/CnXisy9MC_.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions