-
Notifications
You must be signed in to change notification settings - Fork 671
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
InvalidDocblock when annotating promoted property with @var only #6857
Comments
I found these snippets: https://psalm.dev/r/f99085fcfb<?php
final class A
{
public function __construct(
/**
* @var iterable<string>
*/
private iterable $strings,
) {
}
}
https://psalm.dev/r/c33004265b<?php
final class A
{
public function __construct(
/**
* @psalm-readonly
*/
private string $string,
) {
}
private function mutateString(): void
{
$this->string = '';
}
}
|
Yeah, please open a new issue for the second example |
The error is caused by #6764 , Psalm thinks |
I'll think about it this afternoon. This issue dug up the exact problem we were trying to solve by forbidding to have more than one type. At worse, we could have something like /**
* @param int $param
*/
public function __construct(
/**
* @var string
*/
private float $param,
) {
} And we have to decide what to do with that |
The most natural way to do that in Psalm would be:
Those are the rules when there are no promoted properties, but those two rules make the first example fail because the param type becomes To make the example pass, those rules should be applied:
I think it's a little weird to do that because then, there is absolutely no difference between a param docblock and a property in terms of features so why bother using @var here? The first set of rules would also allow this: I'm really conflicted on what to do here. I'm not sure what would be best. @weirdan @ondrejmirtes WDYT? |
I found these snippets: https://psalm.dev/r/3b7fd246d1<?php
class A{
/** @param non-empty-string $param */
public function __construct(
/** @var string */
private string $param,
) {
}
public function setEmpty() {
$this->param = '';
}
}
|
Hi, when I was implementing promoted properties in PHPStan, I wasn't sure how people are going to use it. So PHPStan supports declaring promoted property type through both So in case of constructor In case of I don't know what would happen if someone uses both I don't know if there's some unclear case to take care of, if it is, please ask about that :) |
I think as far as docblocks are concerned we should require |
Thanks for your answers! I'll read that calmly tomorrow and I'll fix that :) |
https://psalm.dev/r/f99085fcfb
Also adding non-type property annotations does not have any effect: https://psalm.dev/r/c33004265b. I can add a separate issue if needed.
The text was updated successfully, but these errors were encountered: