Error: calling impure function `DiemAccount::balance` is not allowed

I am trying to debug public fun balance<Token: store>(addr: address): u64 acquires Balance fn, by adding prints but I get this error:

error: calling impure function `DiemAccount::balance` is not allowed

when I build/run diem-framework.

I do not see definition or even a mention of pure or impure functions in the docs:

https://move-book.com/

I had to comment out ~10 different places of the code just to get prints working.

So problems,

  1. Where to find definition of pure or impure functions in the docs?
  2. How to debug pure fns without the pain I explained above?

Thx!

Hi @simsekgokhan,
These error messages come from errors in type-checking Move prover specs rather than issues with the Move code itself. The pure/impure function distinction is explained in the prover docs here, but I’m guessing that the quickest path to resolving your issue is running cargo run -- --no-doc --no-script-abi --no-script-builder to build the Diem Framework instead of cargo run, This will eliminate all the build steps the include the spec type errors you are running into.

1 Like

Thanks a lot @sam , very helpful!

Your answer made me realize that those errors are actually from Generating script ABIs step. What I need “compiling the modules” step was already done. In short, the prints are actually working even with this error.

cargo r --release -p diem-framework -- --no-doc 
    Finished release [optimized] target(s) in 2.27s
     Running `target/release/diem-framework --no-doc`
Extracting linking/layout APIs from old module bytecodes ... (took 0.050s)
Compiling modules ... (took 1.347s)
Checking linking/layout compatibility ... (took 0.001s)
Generating script ABIs ... error: calling impure function `DiemAccount::balance` is not allowed

     ┌── /home/gsimsek/libra-fork/language/diem-framework/modules/DiemAccount.move:670:19 ───
     │
 670 │         aborts_if balance<Token>(payee) + amount > max_u64() with Errors::LIMIT_EXCEEDED;
     │                   ^^^^^^^^^^^^^^^^^^^^^
     │
     = impure function `DiemAccount::balance(address): u64`

Btw, the command you suggested gives error. But, it is not needed anymore. Problem already fixed.

cargo r --release -p diem-framework -- --no-doc --no-script-abi --no-script-builder
    Finished release [optimized] target(s) in 0.84s
     Running `target/release/diem-framework --no-doc --no-script-abi --no-script-builder`
error: The following required arguments were not provided:
    --no-compiler

USAGE:
    diem-framework --no-compiler --no-doc --no-script-abi --no-script-builder

For more information try --help