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

Operator Overloading #3938

Closed
AndrolGenhald opened this issue Aug 4, 2020 · 2 comments
Closed

Operator Overloading #3938

AndrolGenhald opened this issue Aug 4, 2020 · 2 comments

Comments

@AndrolGenhald
Copy link
Collaborator

I've been using the Decimal extension which overloads the +, -, *, /, %, and ** operators. It would be great if Psalm could support this somehow so I don't have to choose between using the less readable ->add(), ->mul(), etc everywhere and littering code with /** @psalm-suppress */.

I'm ok with any implementation that works, but I'm personally thinking it would be something like annotating a method with

/** 
 * @psalm-overload-operator +
 * @param self|int|string $value
 * @return self
 */

or annotating the class with

/**
 * @psalm-overload-plus self|int|string -> self
 */

It looks like Psalm already supports the operator overloading used by GMP, so hopefully it wouldn't be too much work to add annotations that expose similar functionality.

@psalm-github-bot
Copy link

Hey @AndrolGenhald, can you reproduce the issue on https://psalm.dev ?

@orklah
Copy link
Collaborator

orklah commented Oct 12, 2021

GMP is handled in ArithmeticOpAnalyzer. Feel free to propose a PR with the same handling for Decimal.

We won't add specific annotations for operator overloading unless it's added in PHP core though

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

No branches or pull requests

2 participants