ink icon indicating copy to clipboard operation
ink copied to clipboard

`debug_print(ln)` fails for temporary values

Open xgreenx opened this issue 3 years ago • 3 comments

After https://github.com/paritytech/ink/pull/1258, the debug_print(ln)! macro fails for temporary variables if the "ink-debug" feature is disabled.

image

xgreenx avatar May 18 '22 18:05 xgreenx

I can't reproduce. Building this example with:

cargo +nightly contract build --release

This should disable this feature. The CI would have also caught this error. Can you give more instructions?

athei avatar May 24 '22 06:05 athei

You need to remove "ink-debug" from Cargo.toml=)

xgreenx avatar May 24 '22 07:05 xgreenx

Ahh okay it shouldn't be there. I think it is a left over. Can reproduce it now.

athei avatar May 24 '22 09:05 athei

Can't reproduce the issue with the latest ink! 4.0 release. ink-debug seems not to be in Cargo.toml

SkymanOne avatar Oct 12 '22 15:10 SkymanOne

Looked into it. So the story with ink-debug is that if you execute cargo contract build the default behavior is that cargo-contract builds the contract with --features=ink/ink-debug. That's the reason why the Cargo.toml of the contract-transfer example doesn't need to contain any ink-debug feature anymore.

If you build the contract with cargo contract build --release the debug_print and debug_println macros won't output whatever was passed to them:

if #[cfg(any(feature = "ink-debug", feature = "std"))] {
    …
} else {
    #[macro_export]
    /// Debug messages disabled. Enable the `ink-debug` feature for contract debugging.
    macro_rules! debug_print {
        ($($arg:tt)*) => ();
    }

    #[macro_export]
    /// Debug messages disabled. Enable the `ink-debug` feature for contract debugging.
    macro_rules! debug_println {
        () => ();
        ($($arg:tt)*) => ();
    }
}

(from https://github.com/paritytech/ink/blob/master/crates/env/src/lib.rs).

Hence the bug can no longer occur, as what was a temporary variable in Green's original issue report is swallowed by the macros in case the feature is not enabled.

cmichi avatar Oct 13 '22 06:10 cmichi