Help us shape the future of Go! Take the 2026 Go Developer Survey

forcetypeassert

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 6 Imported by: 29

README

forcetypeassert

godoc.org

forcetypeassert finds type assertions which did forcely such as below.

func f() {
	var a interface{}
	_ = a.(int) // type assertion must be checked
}

You need to check if the assertion failed like so:

func f() {
	var a interface{}
	_, ok := a.(int)
	if !ok { // type assertion failed
  		// handle error
	}
}

Documentation

Index

Constants

View Source
const Doc = "forcetypeassert is finds type assertions which did forcely"

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "forcetypeassert",
	Doc:  Doc,
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
	ResultType: reflect.TypeOf((*Panicable)(nil)),
}

Functions

This section is empty.

Types

type Panicable

type Panicable struct {
	// contains filtered or unexported fields
}

Panicable stores panicable type assertions.

func (*Panicable) At

func (p *Panicable) At(i int) ast.Node

At returns the i-th panicable node.

func (*Panicable) Check

func (p *Panicable) Check(n ast.Node) bool

Check checks whether the node may occur panic or not.

func (*Panicable) Len

func (p *Panicable) Len() int

Len is number of panicable nodes.

Directories

Path Synopsis
cmd
forcetypeassert command

Jump to

Keyboard shortcuts

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