Description
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