ptrtoerr

package module
v0.0.0-...-89ed61e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2020 License: MIT Imports: 5 Imported by: 0

README

ptrtoerr

Detects conversion from pointer to error interface.

Usage

go get github.com/makiuchi-d/ptrtoerr/cmd/ptrtoerr
go vet -vettool `which ptrtoerr` <your-source.go>

Example

example.go
package main

import "fmt"

type MyErr struct {
	error
}

func F() *MyErr {
	return nil // nil pointer, not nil interface
}

func F2() error {
	return F() // nil pointer is not a nil error
}

func main() {
	var err error

	err = F() // nil pointer is not a nil error
	if err != nil {
		fmt.Println("err is not nil")
	}

	err = F2()
	if err != nil {
		fmt.Println("err is not nil")
	}
}
Result
$ go vet -vettool `which ptrtoerr` example.go
# command-line-arguments
testdata/t.go:14:2: Return pointer as error
testdata/t.go:20:2: Assign pointer to error

Documentation

Index

Constants

View Source
const Doc = "ptrtoerr detects assignment pointer value to error interface."

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "ptrtoerr",
	Doc:  Doc,
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL