Skip to content

Method.ReturnsError is not a proper interface/implements check #80

@drshriveer

Description

@drshriveer

I have code that implements a more advanced error model which is passed around as its own interface rather than error (which it does, implement). The code:

https://github.com/hexdigest/gowrap/blob/master/generator/types.go#L95

Dees not do an error interface check and therefore does not work for anything except a literal error type. A proper type check would look something like:

var paramType ast.Type
types.Implements(paramType, ErrorInterface)

where:

// ErrorInterface defines the error interface as a type for comparison.
var ErrorInterface = types.NewInterfaceType([]*types.Func{
	types.NewFunc(
		0,
		nil,
		"Error",
		types.NewSignatureType(nil, nil, nil, nil,
			types.NewTuple(types.NewVar(0, nil, "", types.Typ[types.String])),
			false)),
}, nil)

Unfortunately this would require a much larger re-writing of the existing code so I'm only filing an issue instead of a fix :(.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions