aptos-labs / aptos-core

Aptos is a layer 1 blockchain built to support the widespread use of blockchain through better technology and user experience.
https://aptosfoundation.org
Other
6.18k stars 3.64k forks source link

[Bug][compiler-v2] ability missing warning comes too late #14490

Closed meng-xu-cs closed 2 weeks ago

meng-xu-cs commented 2 months ago

๐Ÿ› Bug

Compiling the following Move code with V2 compiler

module demo::demo {
    struct S<T: store> has store {
        field: T,
    }

    struct E<T: store> has store, drop {
        entry: S<T>,
    }
}

yields an error at the File Format generation phase:

bug: bytecode verification failed with unexpected status code `FIELD_MISSING_TYPE_ABILITY`. This is a compiler bug, consider reporting it.
  โ”Œโ”€ /<redacted>/test/sources/test.move:1:1
  โ”‚  
1 โ”‚ โ•ญ module demo::demo {
2 โ”‚ โ”‚     struct S<T: store> has store {
3 โ”‚ โ”‚         field: T,
4 โ”‚ โ”‚     }
  ยท โ”‚
8 โ”‚ โ”‚     }
9 โ”‚ โ”‚ }
  โ”‚ โ•ฐโ”€^

Which is a bit late in the process.

With V1 compiler, the error message is more dev-friendly:

error[E05001]: ability constraint not satisfied
  โ”Œโ”€ /<redacted>/test/sources/test.move:7:16
  โ”‚
2 โ”‚     struct S<T: store> has store {
  โ”‚            - To satisfy the constraint, the 'drop' ability would need to be added here
  ยท
7 โ”‚         entry: S<T>,
  โ”‚                ^^^^
  โ”‚                โ”‚
  โ”‚                Invalid field type. The struct was declared with the ability 'drop' so all fields require the ability 'drop'
  โ”‚                The type '(demo=0x97751FCABB9A35CABA546D45C30E91CEB8B4622386C2DBF81B9B6D64A9F53AEF)::demo::S<_>' does not have the ability 'drop'
wrwg commented 2 months ago

This is the bytecode verifier as a verification step after code generation, and any error like this is definitely an unintended bug, though safe because the code can't be deployed.