Skip to content

Fix #[cfg(test)] methods in #[contractimpl] blocks failing to compile with testutils #1747

@sisuresh

Description

@sisuresh

Summary

When a pub fn inside a #[contractimpl] block is annotated with #[cfg(test)], the macro correctly propagates that attribute onto the generated __Contract__<method>__invoke_raw_slice function (via #(#attrs)* passthrough in derive_fn). However, derive_contract_function_registration_ctor only received method idents — not their attributes — so the generated registration ctor referenced __Contract__<method>__invoke_raw_slice unconditionally. In a non-test build with the testutils feature enabled, this produces:

error[E0425]: cannot find value `__Contract__persisted__invoke_raw_slice` in this scope

Fix

Change derive_contract_function_registration_ctor to accept (&Ident, &[Attribute]) pairs instead of just &Ident. For each method, extract any cfg attributes and emit them on the corresponding registration call in the ctor body, so #[cfg(test)] (and other cfg guards) are respected.

Impact

Narrow compile-time only: any crate with a #[cfg(test)] public method inside #[contractimpl] would fail to compile with testutils enabled. No runtime behavior is affected.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions