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

Promoted properties missing in extended __construct should report PropertyNotSetInConstructor #10786

Closed
kkmuffme opened this issue Mar 4, 2024 · 3 comments · Fixed by #10817
Labels

Comments

@kkmuffme
Copy link
Contributor

kkmuffme commented Mar 4, 2024

https://psalm.dev/r/b8ed2a83af

Line 15/16 for $name/$foo should report PropertyNotSetInConstructor too

https://psalm.dev/r/83349201cf

Copy link

psalm-github-bot bot commented Mar 4, 2024

I found these snippets:

https://psalm.dev/r/b8ed2a83af
<?php

class A
{
	public function __construct(
		public string $name,
		public string $foo,
	) {}
}

class B extends A
{
    public string $bar;
	public function __construct(
		string $name,
		string $foo,
	) {}
}
Psalm output (using commit 3600d51):

ERROR: PropertyNotSetInConstructor - 13:19 - Property B::$bar is not defined in constructor of B or in any methods called in the constructor
https://psalm.dev/r/83349201cf
<?php

class A
{
    public int $num;
	public function __construct(
		public string $name,
		public string $foo,
	) {
    	$this->num = rand(0,1);
    }
}

class B extends A
{
	public function __construct(
		string $name,
		string $foo,
        int $num,
	) {}
}
Psalm output (using commit 3600d51):

ERROR: PropertyNotSetInConstructor - 14:7 - Property B::$num is not defined in constructor of B or in any methods called in the constructor

@weirdan
Copy link
Collaborator

weirdan commented Mar 4, 2024

Not on lines 15/16 (those are not properties), but yes, PropertyNotSetInConstructor should be reported on the child class, similar to what we have for traditional properties: https://psalm.dev/r/8b9ddbf888

Copy link

I found these snippets:

https://psalm.dev/r/8b9ddbf888
<?php

class A
{
    public string $name;
    public string $foo;
	public function __construct(
		string $name,
		string $foo,
	) {
        $this->name = $name;
        $this->foo = $foo;
    }
}

class B extends A
{
    public string $bar;
	public function __construct(
		string $name,
		string $foo,
	) {}
}
Psalm output (using commit 3600d51):

ERROR: PropertyNotSetInConstructor - 18:19 - Property B::$bar is not defined in constructor of B or in any methods called in the constructor

ERROR: PropertyNotSetInConstructor - 16:7 - Property B::$name is not defined in constructor of B or in any methods called in the constructor

ERROR: PropertyNotSetInConstructor - 16:7 - Property B::$foo is not defined in constructor of B or in any methods called in the constructor

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