essential-contributions / pint

Pint, the constraint-based programming language for declarative blockchains
Apache License 2.0
17 stars 5 forks source link

Cannot access a `storage map` with an `alias` for a `union` #963

Closed lethalgem closed 2 days ago

lethalgem commented 3 weeks ago

I believe this is a bug. If not, please let me know and I'll close the issue.

union MyUnion = x | a(bool) | b(b256) | c(int) | d({ int, b256 }) | e({ b256, bool });
type MyAlias = MyUnion;

storage {
    a: (MyAlias => bool),
}

predicate Test() {
    let a = mut storage::a[MyAlias::d({ 576, 0x0000000000000003000000000000000400000000000000030000000000000004 })];
    constraint a == false;
}

results in 

Error: unknown union
   ╭─[test.pnt:9:28]
   │
 9 │     let a = mut storage::a[MyAlias::d({ 576, 0x0000000000000003000000000000000400000000000000030000000000000004 })];
   │                            ─────┬────  
   │                                 ╰────── union declaration for `::MyAlias::d` not found
───╯
Error: attempt to index a storage map with a mismatched value
   ╭─[test.pnt:9:28]
   │
 9 │     let a = mut storage::a[MyAlias::d({ 576, 0x0000000000000003000000000000000400000000000000030000000000000004 })];
   │                            ───────────────────────────────────────────┬───────────────────────────────────────────  
   │                                                                       ╰───────────────────────────────────────────── storage map access must be with a `::MyAlias (::MyUnion)` variant
   │ 
   │ Note: found access using type `Error`
───╯

if the storage map is accessed with the union it will work properly

union MyUnion = x | a(bool) | b(b256) | c(int) | d({ int, b256 }) | e({ b256, bool });
type MyAlias = MyUnion;

storage {
    a: (MyAlias => bool),
}

predicate Test() {
    let a = mut storage::a[MyUnion::d({ 576, 0x0000000000000003000000000000000400000000000000030000000000000004 })]; // Using MyUnion here
    constraint a == false;
}
mohammadfawaz commented 3 weeks ago

Good catch.

otrho commented 3 weeks ago

Argh, this shouldn't be a thing any more. :(