Skip to content

Fix mock generation for default-valued parameters with underscore labels#209

Merged
dfed merged 7 commits intomainfrom
dfed--fix-underscore-inner-label
Apr 4, 2026
Merged

Fix mock generation for default-valued parameters with underscore labels#209
dfed merged 7 commits intomainfrom
dfed--fix-underscore-inner-label

Conversation

@dfed
Copy link
Copy Markdown
Owner

@dfed dfed commented Apr 4, 2026

Summary

  • Default-valued init parameters whose call-site label is _ (e.g., _ flag: Bool = false or _: Bool = false) are now skipped in mock generation — _ cannot be used as a parameter name, so the init's default value applies silently.
  • For parameters with a usable outer label but _ as the inner label (e.g., isLoggingEnabled _: Bool = false), the outer label is used as the mock parameter name via argument.label.
  • Updates documentation in Manual.md to describe this behavior.

Test plan

  • mock_usesOuterLabelForChildMock_whenDefaultValuedParameterHasUnderscoreInnerLabel
  • mock_usesOuterLabelForRootMock_whenDefaultValuedParameterHasUnderscoreInnerLabel
  • mock_doesNotBubbleDefaultValuedParameter_whenOuterLabelIsUnderscore
  • mock_doesNotBubbleDefaultValuedParameterForChildMock_whenOuterLabelIsUnderscore
  • mock_doesNotBubbleDefaultValuedParameter_whenOnlyLabelIsUnderscore
  • mock_doesNotBubbleDefaultValuedParameterForChildMock_whenOnlyLabelIsUnderscore
  • Full test suite passes (657 tests)
  • SwiftFormat clean

🤖 Generated with Claude Code

When an init parameter uses `_` as the inner label (e.g., `isLoggingEnabled _: Bool = false`),
mock generation was using `_` as the parameter name, producing invalid code like
`_: @autoclosure @escaping () -> Bool = false` and `let _ = _()`.

Now uses the outer label when the inner label is `_`, matching the call-site convention.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.92%. Comparing base (2e01710) to head (ef4173d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #209   +/-   ##
=======================================
  Coverage   99.92%   99.92%           
=======================================
  Files          40       40           
  Lines        5354     5357    +3     
=======================================
+ Hits         5350     5353    +3     
  Misses          4        4           
Files with missing lines Coverage Δ
Sources/SafeDICore/Generators/ScopeGenerator.swift 100.00% <100.00%> (ø)
Sources/SafeDICore/Models/Initializer.swift 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dfed dfed self-assigned this Apr 4, 2026
dfed and others added 2 commits April 4, 2026 08:26
- Split test into two (child mock + root mock) per one-assertion-per-test rule
- Use if/else instead of bare if with early return per code style rules
- SwiftFormat cleanup

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…label

Instead of trying to generate mock parameters for default-valued init
arguments whose call-site label is `_`, skip them entirely — `_` is not
a valid parameter name. The init default value applies silently.

For `outer _: Type = default` (inner label is `_` but outer label is
usable), use `argument.label` (the outer label) as the mock parameter name.

Removes the now-unnecessary `mockPropertyLabel` computed property. The
simpler `argument.label` handles all cases since `_`-labeled params are
filtered out before they reach parameter naming.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dfed dfed changed the title Fix mock generation for underscore inner label parameters Fix mock generation for default-valued parameters with underscore labels Apr 4, 2026
dfed and others added 3 commits April 4, 2026 10:28
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dfed dfed merged commit 73f8354 into main Apr 4, 2026
19 checks passed
@dfed dfed deleted the dfed--fix-underscore-inner-label branch April 4, 2026 21:13
dfed added a commit that referenced this pull request Apr 4, 2026
- Merge main (underscore-label mock tests from PR #209)
- Add comprehensive scanner tests for generateMock detection
- Update mock generation manual example to match doc style
- Use DEBUG in mockConditionalCompilation example

Co-Authored-By: Claude Opus 4.6 (1M context) <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