aptos-core icon indicating copy to clipboard operation
aptos-core copied to clipboard

[Bug][move-compiler-v2] unbound function module in function_info.move:99:12

Open brmataptos opened this issue 9 months ago • 1 comments

🐛 Bug

@movekevin reports that a user reports:

I started getting recently these kind of errors on deployment:
error: unbound module
   ┌─ /home/.../move/https___github_com_aptos-labs_aptos-core_git_main/aptos-move/framework/aptos-framework/sources/function_info.move:99:12
   │
99 │     friend aptos_framework::function_info_tests;
   │            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unbound module '(aptos_framework=0x1)::function_info_tests'

brmataptos avatar May 06 '24 21:05 brmataptos

I've managed to see this problem intermittently but can't reproduce it reliably. I think that (1) the libraries are being built without #[test_only] code, but then a user #[test] function which includes module aptos_framework::function_info may wind up parsing the #[test_only] friend ... at the end of that module which refers to a module (function_info_tests) which doesn't exist in the current compilation environment. The right solution may be to fix the compiler to silently ignore a friend declaration referring to an unknown module.

File aptos-move/framework/aptos/framework/tests/function_info_tests_.move has:

#[test_only]
module aptos_framework::function_info_tests {
...
}

and file aptos-move/framework/aptos-framework/sources/function_info.move has:

/// The `function_info` module defines the `FunctionInfo` type which simulates a function pointer.
module aptos_framework::function_info {
...
    // Test only dependencies so we can invoke those friend functions.
    #[test_only]
    friend aptos_framework::function_info_tests;
}

I think the problem is that (1) the #[test_only] code is excluded from the compiled Aptos Framework, but the

brmataptos avatar May 10 '24 19:05 brmataptos

This has been hard to reproduce, but I found it happening in a case where I had files from a previous build/tool left behind in a Move package build/ directory, which were found by the move-package mechanism to search for dependency source files.

We'll close this with 3 followup issues:

  • [Urgent] add documentation for users to consider running aptos move clean if they have strange problems [#13320],
  • [High] add a mechanism to optionally show the list of source files compiled [#13321]
  • [High] add a mechanism to check for conflicting input package files and warn about them. [#13322]

brmataptos avatar May 17 '24 17:05 brmataptos