Skip to content

Conversation

@dotdash
Copy link
Contributor

@dotdash dotdash commented Dec 22, 2025

Currently we're only handling docblocks that are tied to a statement, and only consider a single docblock to be tied to any given statement. This means that having multiple consecutive docblocks to declare variables, for example in a classic PHP-only template file, will have us only considering the last of these docblocks. We can improve this by treating all consecutive docblocks that preceed a given statement, only separated by whitespace or comments, to apply to that statement.

This uncovered a bug in the docblock_var_on_non_assignment testcase which actually didn't test what it was supposed to test because the extra docblock was ignored. With the new behaviour, that test actually complains that the docblock is redundant because it doesn't narrow the known type. We can widen the original type and add a call that actually requires the type-narrowing docblock to be processed.

We can also adjust the test case for issue #801 because we now fully support the original code.

📌 What Does This PR Do?

Properly handles multiple consecutive docblocks.

🔍 Context & Motivation

All but the last of a set of consecutive docblocks are currently ignore. This fixes this to process all docblocks

🛠️ Summary of Changes

  • Bug Fix: Fixed docblocks being ignored.

📂 Affected Areas

  • Analyzer
  • Linter
  • Formatter
  • CLI
  • Composer Plugin
  • Dependencies
  • Documentation
  • Other (please specify):

🔗 Related Issues or PRs

Fully resolves #801

📝 Notes for Reviewers

<3

Currently we're only handling docblocks that are tied to a statement,
and only consider a single docblock to be tied to any given statement.
This means that having multiple consecutive docblocks to declare
variables, for example in a classic PHP-only template file, will have us
only considering the last of these docblocks. We can improve this by
treating all consecutive docblocks that preceed a given statement, only
separated by whitespace or comments, to apply to that statement.

This uncovered a bug in the docblock_var_on_non_assignment testcase
which actually didn't test what it was supposed to test because the
extra docblock was ignored. With the new behaviour, that test actually
complains that the docblock is redundant because it doesn't narrow the
known type. We can widen the original type and add a call that actually
requires the type-narrowing docblock to be processed.

We can also adjust the test case for issue carthage-software#801 because we now fully
support the original code.
@azjezz azjezz merged commit 2566e57 into carthage-software:main Dec 23, 2025
6 checks passed
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.

analyzer: var doc comment is still tied to a statement

2 participants