Skip to content

fix: factory pattern should check all conditional reassignments#24

Merged
mpyw merged 2 commits intomainfrom
fix/factory-conditional-reassignment
Dec 26, 2025
Merged

fix: factory pattern should check all conditional reassignments#24
mpyw merged 2 commits intomainfrom
fix/factory-conditional-reassignment

Conversation

@mpyw
Copy link
Owner

@mpyw mpyw commented Dec 26, 2025

Summary

  • Fixed BlockReturnsContextUsingFunc to only check what's actually returned, not short-circuit on any nested func literal
  • Added recursive context-checking for nested factories (triple higher-order patterns)
  • Created funcLitAssignmentsAllUseOrReturnContext to verify ALL assignments from last unconditional onwards
  • Added FuncLitAssignment type and related methods to assignment.go for tracking conditional vs unconditional assignments

Test plan

  • Added test cases for factory conditional reassignment patterns
  • All existing tests pass (verified with ./test_all.sh)

🤖 Generated with Claude Code

The factory.go had a bug where BlockReturnsContextUsingFunc was
short-circuiting when it found ANY nested func literal that uses
context, even if that func wasn't actually returned.

Fixed by:
- Removing the short-circuit and only checking what's actually returned
- Adding recursive context-checking for nested factories
- Creating funcLitAssignmentsAllUseOrReturnContext to check ALL
  assignments from last unconditional onwards

Also added FuncLitAssignment type and related methods to assignment.go
to track conditional vs unconditional assignments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Dec 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.25%. Comparing base (e8659b1) to head (fa3d081).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #24      +/-   ##
==========================================
+ Coverage   84.18%   84.25%   +0.06%     
==========================================
  Files          24       24              
  Lines        1834     1842       +8     
==========================================
+ Hits         1544     1552       +8     
  Misses        173      173              
  Partials      117      117              
Flag Coverage Δ
unittests 84.25% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

mpyw added a commit that referenced this pull request Dec 26, 2025
Resolved conflict in internal/probe/assignment.go:
- Kept FuncLitsAssignedTo from main
- Removed duplicate FuncLitAssignmentsOfIdent (already added in main via PR #24)
@mpyw mpyw merged commit d8f708e into main Dec 26, 2025
12 checks passed
@mpyw mpyw deleted the fix/factory-conditional-reassignment branch December 26, 2025 03:40
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