Error when generateMock: true conflicts with user-defined mock method#214
Merged
Error when generateMock: true conflicts with user-defined mock method#214
Conversation
When an @INSTANTIABLE type has both `generateMock: true` and a hand-written `mock()` method, emit a macro diagnostic with a fix-it that removes `generateMock: true` from the attribute. Previously this was silently handled at the tool level by skipping generation. Now it's caught at compile time with a clear error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #214 +/- ##
=======================================
Coverage 99.94% 99.94%
=======================================
Files 40 40
Lines 5601 5648 +47
=======================================
+ Hits 5598 5645 +47
Misses 3 3
🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The method is only called when generateMockValue is true, which guarantees arguments exist. The guard was dead code that hurt coverage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add @mainactor to multi-argument test so the rewriter visits a non-matching attribute, covering the else branch. Also add a negative test confirming no diagnostic when generateMock is not set. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@Instantiabletype has bothgenerateMock: trueand a hand-writtenmock()method, the macro now emits a compile-time error with a fix-it to removegenerateMock: true.@Instantiabletypes.Test plan
producesDiagnostic_whenGenerateMockIsTrueAndUserDefinedMockExists— single-argument attribute, fix-it removes entire argument clauseproducesDiagnostic_whenGenerateMockIsTrueAndUserDefinedMockExistsWithOtherArguments— multi-argument attribute, fix-it removes onlygenerateMock: truemockMethodConflictsWithGenerateMock_description_mentionsBothGenerateMockAndMockMethodmockMethodConflictsWithGenerateMock_fixIt_mentionsRemovingGenerateMock🤖 Generated with Claude Code