Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing dynamic fields (must for Sui) #72

Open
jcivlin opened this issue Jun 19, 2024 · 0 comments
Open

Fixing dynamic fields (must for Sui) #72

jcivlin opened this issue Jun 19, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@jcivlin
Copy link
Collaborator

jcivlin commented Jun 19, 2024

Move allows generic structures. We support them if they are explicitly instantiated, but they me also be instantiated in an instantiation of a generic function call.
Here is an example:

module 0x1::dynamic_structure {
    struct Inner<K, V> has copy, drop, store {
        key: K,
        val: V,
    }

    struct DynamicStruct<S: drop> has copy, drop, store {
        id: u64,
        s: S,
    }

    public fun dynamic_struct<K: drop, V: drop>(id: u64, key: K, val: V) {
        DynamicStruct {
            id,
            s: Inner { key, val },
        };
    }
    public fun test_fail() {
        // If code is open then `dynamic_struct` is instantiated explicitly and
        // `dynamic_struct` call below will not fail.
        // DynamicStruct {
        //     id: 44,
        //     s: Inner { key: 1, val: 2 },
        // };

        // this was failing before commit `061824-fixing-dynamic-fields`
        dynamic_struct(44, 1, 2);
    }
}

Here we have two generic structure Inner and DynamicStruct and generic function dynamic_struct that instantiates DynamicStruct while using types/values passed as the arguments.

if we uncomment the explicit instantiation of DynamicStruct in the function test_fail, then everything will be compiling, since all structures will be instantiated explicitly.

But without this explicit instantiation (with the comments not removed) the call dynamic_struct(44, 1, 2) will fail in compilation, since implicitly used structures had not been instantiated.

It is important to fix, since Sui framework uses this construct in abundance, see:
sui/crates/sui-framework/packages/sui-framework

@jcivlin jcivlin added the bug Something isn't working label Jun 19, 2024
@jcivlin jcivlin self-assigned this Jun 19, 2024
@jcivlin jcivlin changed the title Sui Code Bug or Feature Request Fixing dynamic fields (must for Sui) Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant