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

Using stub causes PropertyNotSetInConstructor #2319

Open
weirdan opened this issue Nov 10, 2019 · 6 comments
Open

Using stub causes PropertyNotSetInConstructor #2319

weirdan opened this issue Nov 10, 2019 · 6 comments

Comments

@weirdan
Copy link
Collaborator

weirdan commented Nov 10, 2019

Steps to reproduce

  • git clone [email protected]:weirdan/psalm-bug-PropertyNotSetInConstructor-with-stub.git
  • cd psalm-bug-PropertyNotSetInConstructor-with-stub
  • composer install
  • vendor/bin/psalm --no-cache

Expected

No issues. Stub with constructor body, without constructor body and without constructor at all - all of those cases should not cause PropertyNotSetInConstructor.

Actual

$ vendor/bin/psalm --no-cache
Scanning files...
Analyzing files...

░░E

ERROR: PropertyNotSetInConstructor - src/ClientClass.php:5:16 - Property Weirdan\Tt\Library\BaseLibraryClass::$prop is not defined in constructor of Weirdan\Tt\ClientClass and in any methods called in the constructor
abstract class ClientClass extends LibraryClass


------------------------------
1 errors found
------------------------------

Checks took 0.34 seconds and used 26.717MB of memory
Psalm was able to infer types for 100% of the codebase

Additional observations

Running with stubs disabled (vendor/bin/psalm --no-cache -c psalm-no-stubs.xml) produces no issues:

$ vendor/bin/psalm --no-cache -c psalm-no-stubs.xml
Scanning files...
Analyzing files...

░░░

------------------------------
No errors found!
------------------------------

Checks took 0.43 seconds and used 26.714MB of memory
Psalm was able to infer types for 100% of the codebase

References

Originally reported in psalm/psalm-plugin-doctrine#30

@paxal
Copy link
Contributor

paxal commented Nov 18, 2019

Same here with non-stub : https://psalm.dev/r/6e1df08edd

@muglug muglug added the bug label Nov 27, 2019
@weirdan
Copy link
Collaborator Author

weirdan commented Nov 30, 2020

Same here with non-stub : psalm.dev/r/6e1df08edd

This doesn't fail anymore, but the original issue still reproduced as described.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/6e1df08edd
<?php
  
class A {
  /** @var int */
  protected $a;
  public function __construct() {
    $this->a = 1;
  }
  public function __toString(): string {
  	return (string) $this->a;
  }
}

class B extends A {
}

class C extends B {
  public function __construct() {
    parent::__construct();
  }
}

echo (string) (new C());
Psalm output (using commit eeb9cb0):

No issues!

@Jean85
Copy link
Contributor

Jean85 commented Mar 23, 2021

I'm still affected by this, any way to fix it?

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Dec 13, 2021

If #7110 doesn't fix this directly, it should at least make the fix possible.

Edit: Well, maybe, maybe not. That issue is more about loading stubs when the class doesn't appear in the code, this may have more to do with stubs correctly overriding a class that appears in the code.

@weirdan
Copy link
Collaborator Author

weirdan commented Feb 12, 2024

Looks like I have deleted reproducer repo.

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

5 participants