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

Parent with promoted properties in __construct should imply @psalm-consistent-constructor and report errors if properties are not set #10785

Closed
kkmuffme opened this issue Mar 4, 2024 · 2 comments

Comments

@kkmuffme
Copy link
Contributor

kkmuffme commented Mar 4, 2024

https://psalm.dev/r/2176853490

  1. if a __construct has promoted properties, this should imply @psalm-consistent-constructor

  2. @psalm-consistent-constructor should report errors not only for the type but also for promoted properties (or the lack thereof in the implementing class), since you'd end up with uninitialized(string) in the example above otherwise.

Copy link

I found these snippets:

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

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

class B extends A
{
	public function __construct(
		string $names,
		int $foo,
	) {}
}

$b = new B('hello', 15);

$x = $b->name;
/** @psalm-trace $x */;

$y = $b->foo;
/** @psalm-trace $y */;
Psalm output (using commit 3600d51):

INFO: Trace - 22:23 - $x: string

INFO: Trace - 25:23 - $y: string

INFO: UnusedVariable - 21:1 - $x is never referenced or the value is not used

INFO: UnusedVariable - 24:1 - $y is never referenced or the value is not used

@kkmuffme
Copy link
Contributor Author

kkmuffme commented Mar 4, 2024

Closed in favor of #10786

@kkmuffme kkmuffme closed this as not planned Won't fix, can't repro, duplicate, stale Mar 4, 2024
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

No branches or pull requests

1 participant