Skip to content

Fix proc-macro panics and wrong context types (#127); clean up macro code (#124)#128

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/fix-macro-bugs-and-add-tests
Closed

Fix proc-macro panics and wrong context types (#127); clean up macro code (#124)#128
Copilot wants to merge 2 commits intomainfrom
copilot/fix-macro-bugs-and-add-tests

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

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 = false panics: resolve_context was called with the full #[mitosis(...)] attribute; ContextArgs::from_meta hit the unknown use_randmut field and .unwrap() panicked. Fixed by ignoring attributes that don't parse as ContextArgs.

  • Wrong context type in Mitosis create_context: mitosis_derive passed RandomlyMutable as the trait name to the context helper, generating fields typed as <T as RandomlyMutable>::Context instead of <T as Mitosis>::Context. Fixed by passing Mitosis.

  • Empty struct produces invalid syntax: No-field structs left ctx_ident as None, emitting type Context = ;. Fixed by defaulting to ().

  • Tuple index suffix: #i where i: usize emitted self.0usize. Fixed using syn::Index::from(i).

Code Improvements

Replaced the old create_context_helper with a resolve_context function backed by ContextKind/ContextInfo types, removing the ambiguous custom_context: bool flag and replacing imperative Vec::push loops with iterator chains.

Example (previously panicked at compile time)

// use_randmut = false took the non-early-return path and panicked
#[derive(Clone, Mitosis)]
#[mitosis(use_randmut = false)]
struct Foo { field: MyField }

// create_context on Mitosis generated RandomlyMutable::Context fields,
// causing type mismatches when Mitosis::Context != RandomlyMutable::Context
#[derive(Clone, Mitosis)]
#[mitosis(create_context(name = FooCtx, derive(Clone, Default)))]
struct Bar { a: TypeA, b: TypeB }

Tests

Added genetic-rs/tests/derive_macros.rs with 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.

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
Copilot AI requested a review from HyperCodec February 23, 2026 18:36
@HyperCodec HyperCodec marked this pull request as ready for review February 23, 2026 18:43
@HyperCodec
Copy link
Owner

wait why is this merging into main I specified dev

@HyperCodec HyperCodec closed this Feb 23, 2026
@HyperCodec HyperCodec deleted the copilot/fix-macro-bugs-and-add-tests branch February 23, 2026 19:06
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.

new update causes panic in macros macro code is terrible

2 participants