Skip to content

feat: infer property types from constructor assignments#81

Merged
AJenbo merged 1 commit intoAJenbo:mainfrom
lucasacoutinho:fix/untyped-property-chain-resolution
Apr 10, 2026
Merged

feat: infer property types from constructor assignments#81
AJenbo merged 1 commit intoAJenbo:mainfrom
lucasacoutinho:fix/untyped-property-chain-resolution

Conversation

@lucasacoutinho
Copy link
Copy Markdown
Contributor

Properties without explicit type declarations can now have their types inferred when they’re assigned using new ClassName().

This works in both cases:
Promoted constructor parameters with defaults (e.g. private $repo = new Repository())
Assignments inside the constructor (e.g. $this->repo = new Repository())

As a result, features like go-to-definition and autocomplete work correctly for chained calls such as $this->repo->findById(), even when the property itself isn’t typed. This is especially useful for legacy codebases and modern PHP 8.1+ patterns that rely on inline object instantiation.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 9, 2026

Codecov Report

❌ Patch coverage is 86.04651% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.03%. Comparing base (50e46d2) to head (981d252).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/parser/classes.rs 78.43% 11 Missing ⚠️
src/completion/phpdoc/generation.rs 97.14% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #81   +/-   ##
=======================================
  Coverage   87.02%   87.03%           
=======================================
  Files         153      153           
  Lines       93589    93673   +84     
=======================================
+ Hits        81450    81526   +76     
- Misses      12139    12147    +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lucasacoutinho lucasacoutinho marked this pull request as draft April 10, 2026 00:41
@lucasacoutinho lucasacoutinho force-pushed the fix/untyped-property-chain-resolution branch from d61bad6 to c0906f2 Compare April 10, 2026 00:57
@lucasacoutinho lucasacoutinho marked this pull request as ready for review April 10, 2026 00:57
@AJenbo AJenbo force-pushed the fix/untyped-property-chain-resolution branch from c0906f2 to 981d252 Compare April 10, 2026 20:07
@AJenbo AJenbo merged commit e567582 into AJenbo:main Apr 10, 2026
7 checks passed
@AJenbo
Copy link
Copy Markdown
Owner

AJenbo commented Apr 11, 2026

Interesting addition, personally I think projects should just hint there code properly since there's a lot of pitfalls in trying to infer from code what the signature should be, but this is nicely contained.

I added an extra check to make sure it doesn't trigger if there's any other forms of types on the property. I also hooked it up to the PHPDoc generation logic which adds a nice syngery effect where the LSP can now generate plausible types which the developer can then correct in necessary.

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

Successfully merging this pull request may close these issues.

3 participants