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

dsl: add ExprType.HasMethod() #349

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions dsl/dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ func (ExprType) ConvertibleTo(typ string) bool { return boolResult }
// See https://golang.org/pkg/go/types/#Implements.
func (ExprType) Implements(typ typeName) bool { return boolResult }

// HasMethod reports whether a type has a given method.
// Unlike Implements(), it will work for both value and pointer types.
//
// fn argument is a function signature, like `WriteString(string) (int, error)`.
// It can also be in form of a method reference for importable types: `io.StringWriter.WriteString`.
//
// To avoid confusion with Implements() method, here is a hint when to use which:
//
// - If you want to check if it's possible to call F on x, use HasMethod().
// - If you want to know if you can pass x as I interface, use Implements().
func (ExprType) HasMethod(fn string) bool { return boolResult }

// Is reports whether a type is identical to a given type.
func (ExprType) Is(typ string) bool { return boolResult }

Expand Down