Compiler crash []

repro, git@github.com:shiqicao/move_repro.git
version, sui 1.7.0-362c5c3f2

stack

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', external-crates/move/move-compiler/src/sui_mode/id_leak.rs:138:56
stack backtrace:
2023-08-11T23:40:28.412189Z ERROR telemetry_subscribers: panicked at 'called `Option::unwrap()` on a `None` value', external-crates/move/move-compiler/src/sui_mode/id_leak.rs:138:56 panic.file="external-crates/move/move-compiler/src/sui_mode/id_leak.rs" panic.line=138 panic.column=56
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: <move_compiler::sui_mode::id_leak::IDLeakVerifierAI as move_compiler::cfgir::visitor::SimpleAbsInt>::exp_custom
   4: move_compiler::cfgir::visitor::SimpleAbsInt::exp
   5: <V as move_compiler::cfgir::visitor::AbstractInterpreterVisitor>::verify
   6: move_compiler::cfgir::translate::visit_function
   7: move_compiler::cfgir::translate::program
   8: move_compiler::command_line::compiler::run
   9: move_compiler::command_line::compiler::run
  10: move_compiler::command_line::compiler::run
  11: move_compiler::command_line::compiler::run
  12: move_compiler::command_line::compiler::run
  13: move_compiler::command_line::compiler::SteppedCompiler<_>::run
  14: move_compiler::command_line::compiler::Compiler::run
  15: move_compiler::command_line::compiler::Compiler::build
  16: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  17: move_package::compilation::compiled_package::CompiledPackage::build_all
  18: move_package::compilation::build_plan::BuildPlan::compile_with_driver
  19: sui_move_build::build_from_resolution_graph
  20: sui_move_build::BuildConfig::build
  21: sui_move::build::Build::execute_internal
  22: sui_move::build::Build::execute
  23: sui_move::execute_move_command
  24: sui::sui_commands::SuiCommand::execute::{{closure}}
  25: tokio::runtime::park::CachedParkThread::block_on
  26: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
  27: tokio::runtime::runtime::Runtime::block_on
  28: sui::main
2 Likes

@shiqicao noticing that it happens on build time.

You’re trying to construct a struct outside of its definition module, which is not possible (as they are private).

To generate a struct outside of the defining module, you’d need a function that creates a struct and returns it inside the foo module itself.

e.g.

public fun create_foo(): Foo {
    Foo {}
}

But, keep in mind that this is a public function and anyone could create a struct of type Foo. There are a few ways to guard this:

  1. Adding some business logic based on which you’d return a Foo.
  2. Using a public(friend) function and making the module a friend.
  3. Authentication mechanisms to protect it. (Suifrens uses this technique)

Also, it’s recommended you use the Sui Move Analyzer to catch these issues earlier and improve your development experience!

1 Like

This is a bug report for the compiler, it is a must fix.

2 Likes