Skip to content

Resolve $this->method() return type in typescope - #12

Merged
TomasVotruba merged 1 commit into
mainfrom
typescope-method-return
Nov 8, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
typescope-method-return

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Extends typescope so a value flowing out of a local method call resolves to the method's declared return type.

  • The scope collector records each method's declared return type by name (case-insensitive, as PHP resolves method names).
  • inferValueType gains an ExprMethodCall case: a $this->method() call resolves to that method's return type, so ResolveType / ResolveValue / ResolveClass all follow it.

Scope matches the existing resolver: single native types only. A missing return type, a union/intersection, or a call on anything but $this stays unresolved; a nullable return keeps its inner type (?User -> User).

Unblocks the "method call on a $this->getUser() result" case for downstream consumers.

inferValueType now reads the declared return type of a $this->method()
call from the collected class subtree, so a value flowing out of a local
method resolves to its type. Single native types only; a missing, union,
or non-$this return stays unresolved, and a nullable return keeps its
inner type.
@TomasVotruba
TomasVotruba merged commit 92d1ad1 into main Nov 8, 2026
5 checks passed
@TomasVotruba
TomasVotruba deleted the typescope-method-return branch November 8, 2026 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant