Type Propagation With Numerics #6371
Labels
audit-report
Related to the audit report
bug
Something isn't working
P: high
Should be looked at if there are no critical issues left
CS-FSSA-005
Variables in Sway are strongly typed i.e., there cannot be any implicit changes in their type. Consider the
following example:
In the example, we define MyTrait which we then implement for u32 and u64. Moreover, we implement
function baz for these types. In main() we declare variable a. Since a is assigned a literal with no type
ascription, it is initially typed as numeric. We execute bar(a). The type checker at this point will
resolve to
bar::<u64>
and eventually calls foo() for u64 which logs 64. This means that a should betyped as u64. However, we later assign a reference of a to x which is explicitly typed as &u32 which
coerces a to u32. We later, call a.baz() which calls foo() for u32 and logs 32. This script is
successfully compiled and executed as described, implying a type-propagation failure.
The text was updated successfully, but these errors were encountered: