Fix proc-macro panics and wrong context types (#127); clean up macro code (#124)#128
Closed
Fix proc-macro panics and wrong context types (#127); clean up macro code (#124)#128
Conversation
This was
linked to
issues
Feb 23, 2026
Closed
Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix macro bugs and add test cases for future prevention
Fix proc-macro panics and wrong context types (#127); clean up macro code (#124)
Feb 23, 2026
HyperCodec
approved these changes
Feb 23, 2026
Owner
|
wait why is this merging into main I specified dev |
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.
The 1.2.0 macro rewrite introduced several bugs causing compile-time proc-macro panics and incorrect context type generation. This PR fixes all of them and improves the macro code structure.
Bugs Fixed
use_randmut = falsepanics:resolve_contextwas called with the full#[mitosis(...)]attribute;ContextArgs::from_metahit the unknownuse_randmutfield and.unwrap()panicked. Fixed by ignoring attributes that don't parse asContextArgs.Wrong context type in
Mitosiscreate_context:mitosis_derivepassedRandomlyMutableas the trait name to the context helper, generating fields typed as<T as RandomlyMutable>::Contextinstead of<T as Mitosis>::Context. Fixed by passingMitosis.Empty struct produces invalid syntax: No-field structs left
ctx_identasNone, emittingtype Context = ;. Fixed by defaulting to().Tuple index suffix:
#iwherei: usizeemittedself.0usize. Fixed usingsyn::Index::from(i).Code Improvements
Replaced the old
create_context_helperwith aresolve_contextfunction backed byContextKind/ContextInfotypes, removing the ambiguouscustom_context: boolflag and replacing imperativeVec::pushloops with iterator chains.Example (previously panicked at compile time)
Tests
Added
genetic-rs/tests/derive_macros.rswith 19 integration tests covering all four derive macros across named structs, tuple structs, empty structs,create_context,with_context, and the specific regression cases above.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.