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

[Bug] Ability error for a struct wrapping a function, but the struct has that ability?

Open vineethk opened this issue 8 months ago • 4 comments
trafficstars

🐛 Bug

Consider the following transactional test:

//# publish
module 0xc0ffee::m {
    struct Func<T> {
        f1: |&T| bool,
    } has copy, drop;

    struct S {
        x: u64,
    }

    fun inspect<T>(f: Func<T>, v: T): T {
        if ((f.f1)(&v)) {
            v
        } else {
            v
        }
    }
    
    fun test(n: u64): S {
        let s = S { x: 42 };
        let f: Func<S> = Func { f1: |r| r.x < n };
        inspect(f, s)
    }
}

Currently, we get the following compiler error:

Error: compilation errors:
 error: local `f` of type `Func<T>` does not have the `drop` ability
   ┌─ TEMPFILE:10:14
   │
10 │         if ((f.f1)(&v)) {
   │              ^ still borrowed but will be implicitly dropped later since it is no longer used

However, f does have the drop ability, and we should not get a compiler error here?

vineethk avatar Mar 21 '25 16:03 vineethk