Skip to content

Conversation

@gnutix
Copy link
Contributor

@gnutix gnutix commented Jan 23, 2026

🤖 Generated with Claude Code regarding issue phpstan/phpstan#13993

Summary

  • Fixed FiberScope::pushInFunctionCall() and popInFunctionCall() which were no-ops, preventing closure parameter types from being properly inferred
  • Removed the FiberScope exclusion in ParametersAcceptorSelector::selectFromArgs() since FiberScope now properly handles function call tracking

Problem

When using FNSR (Fiber Node Scope Resolver, enabled by default on PHP 8.1+), closure parameter types were not being properly inferred from the expected callable type. This caused false positives like:

Parameter $loader expects Closure(Context, non-empty-array<...>): iterable<...>,
Closure(Context, array): Generator<array{mixed, mixed}, ...> given.

The root cause was that FiberScope::pushInFunctionCall() was a no-op (just returning $this), so the inFunctionCallsStack was never populated. This stack is used by getClosureType() to access the expected callable signature and properly infer closure parameter types.

Test plan

  • Verified the regression test cases from #13993 now pass
  • All 1242 NodeScopeResolverTest tests pass
  • TestClosureTypeRuleTest passes

@gnutix gnutix force-pushed the fix/fiberscope-closure-type-inference branch 4 times, most recently from e13aa2a to d9c9179 Compare January 23, 2026 14:28
FiberScope::pushInFunctionCall() and popInFunctionCall() were no-ops,
which prevented the inFunctionCallsStack from being populated when
using FNSR (Fiber Node Scope Resolver).

This caused closure parameter types to not be properly inferred from
the expected callable type when a closure is passed as an argument.

The fix implements proper function call stack tracking in FiberScope
and removes the FiberScope exclusion in ParametersAcceptorSelector.

Fixes #13993

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@gnutix gnutix force-pushed the fix/fiberscope-closure-type-inference branch from d9c9179 to ef0221a Compare January 23, 2026 14:31
The test uses PHP 8.1+ features (Fibers) and tests FiberScope-specific
behavior. Add // lint >= 8.1 comment to skip the test on PHP 7.4 and 8.0.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant