aptos-labs/aptos-core

[Bug][Compiler-v2] index notation does not check ability properly

Closed this issue ยท 0 comments

๐Ÿ› Bug

When compiling the following code,

    struct Wrapper<T: copy> has drop, key, store, copy {
        inner: T
    }

    fun unwrap<T: copy>(self: &Wrapper<T>): T {
        self.inner
    }

    fun dispatch<T: copy>(account: address): T acquires Wrapper {
        unwrap(&Wrapper<T>[account])
    }

The following bytecode verification error is generated:

 bug: bytecode verification failed with unexpected status code `CONSTRAINT_NOT_SATISFIED`. This is a compiler bug, consider reporting it.
Error message: missing abilities for `ImmBorrowGlobalGeneric(StructDefInstantiationIndex(0))` at code offset 1

If we change unwrap(&Wrapper<T>[account]) into unwrap(borrow_global<Wrapper<T>>), the following error is generated:

 error: type `T` is missing required ability `store`
    โ”Œโ”€ TEMPFILE:298:23
    โ”‚
298 โ”‚         borrow_global<Wrapper<T>>(account).unwrap()
    โ”‚                       ^^^^^^^^^^
    โ”‚