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

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

Open
drshriveer opened this issue Oct 18, 2023 · 0 comments
Open

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

drshriveer opened this issue Oct 18, 2023 · 0 comments

Comments

@drshriveer
Copy link

drshriveer commented Oct 18, 2023

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 :(.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant