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
["String is not a valid Move identifier"][!is_valid asusize];
The check using 'out of range' error is not robust as one can easily turn it off by #![allow(conditional_panic)], as shown in this Playground. The program only panics at runtime instead of compile time which is not an expected behavior for ident_str!(...) that is advertised for checking valid identifier at compile time.
I suggest to use a dummy struct with an associated constant that does the assertion of is_valid at compile time like so:
struct_Whatever;impl_Whatever{constIS_VALID:() =
assert!($crate::is_valid(s), "String is not a valid Move identifier");}
_Whatever::IS_VALID;
This is more robust as the macro ident_str expands into {...; _Whatever::IS_VALID; and since _Whatever::IS_VALID is unconditionally evaluated at compile time, this will be a more robust way to check for valid IdentStr at compile time. Playground.
The text was updated successfully, but these errors were encountered:
sui/external-crates/move/crates/move-core-types/src/identifier.rs
Lines 342 to 343 in 7d006ef
The check using 'out of range' error is not robust as one can easily turn it off by
#![allow(conditional_panic)]
, as shown in this Playground. The program only panics at runtime instead of compile time which is not an expected behavior forident_str!(...)
that is advertised for checking valid identifier at compile time.I suggest to use a dummy struct with an associated constant that does the assertion of
is_valid
at compile time like so:This is more robust as the macro
ident_str
expands into{...; _Whatever::IS_VALID;
and since_Whatever::IS_VALID
is unconditionally evaluated at compile time, this will be a more robust way to check for validIdentStr
at compile time. Playground.The text was updated successfully, but these errors were encountered: