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

Conversation

quasilyte
Copy link
Owner

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

Refs #331

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:

	- To check if it's possible to call F on x, use HasMethod(F)
	- To check if x can be passed as I interface, use Implements(I)

Refs #331
@quasilyte quasilyte force-pushed the quasilyte/dsl_type_has_method branch from 314cb01 to 3a246ab Compare January 6, 2022 12:50
@quasilyte quasilyte merged commit 2270a32 into master Jan 6, 2022
@quasilyte quasilyte deleted the quasilyte/dsl_type_has_method branch January 6, 2022 12:51
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

Successfully merging this pull request may close these issues.

1 participant