You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 {
structInner<K, V> hascopy, drop, store {
key: K,
val: V,
}
structDynamicStruct<S: drop> hascopy, drop, store {
id: u64,
s: S,
}
publicfundynamic_struct<K: drop, V: drop>(id: u64, key: K, val: V) {
DynamicStruct {
id,
s: Inner { key, val },
};
}
publicfuntest_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
The text was updated successfully, but these errors were encountered:
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:
Here we have two generic structure
Inner
andDynamicStruct
and generic functiondynamic_struct
that instantiatesDynamicStruct
while using types/values passed as the arguments.if we uncomment the explicit instantiation of
DynamicStruct
in the functiontest_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
The text was updated successfully, but these errors were encountered: