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
The current implementation of type units feels inconsistent and confusing. I would like to remove them from the language in their current form.
Motivation
While working on type checking I keep running into issues with units. All of this is made much more difficult because there is very minimal documentation on the subject.
uint256 is considered "unitless", so assignments such as uint256(wei) = uint256 are permitted. It took me a while to realize this was the case, I assumed uint256 was equivalent to uint256(None) and so should not be compatible with uint256(wei).
Addition and subtraction between values with different units is disallowed, but multiplication and division is allowed and produces new compound unit types. This is completely undocumented and does not feel intuitive to me.
wei_value and uint256(wei), despite both being uint256 with unit wei, are incompatible.
Same for timestamp, timedelta, and uint256(sec). Per the documentation, timestamp additionally cannot be added or subtracted with another timestamp. I was unable to check with this firsthand, as attempting to assign to timestamp or timedelta gives me a TypeMistmatch. These feel broken.
While I'm not inherently opposed to the idea of units, the current implementation feels more confusing than beneficial. I propose we remove units altogether while refactoring. We can revisit the concept once refactoring is complete and documentation is up-to-date, and hopefully come up with another approach that's cleaner and more consistent.
Simple Summary
The current implementation of type units feels inconsistent and confusing. I would like to remove them from the language in their current form.
Motivation
While working on type checking I keep running into issues with units. All of this is made much more difficult because there is very minimal documentation on the subject.
uint256
is considered "unitless", so assignments such asuint256(wei) = uint256
are permitted. It took me a while to realize this was the case, I assumeduint256
was equivalent touint256(None)
and so should not be compatible withuint256(wei)
.wei_value
anduint256(wei)
, despite both beinguint256
with unitwei
, are incompatible.timestamp
,timedelta
, anduint256(sec)
. Per the documentation,timestamp
additionally cannot be added or subtracted with anothertimestamp
. I was unable to check with this firsthand, as attempting to assign totimestamp
ortimedelta
gives me aTypeMistmatch
. These feel broken.While I'm not inherently opposed to the idea of units, the current implementation feels more confusing than beneficial. I propose we remove units altogether while refactoring. We can revisit the concept once refactoring is complete and documentation is up-to-date, and hopefully come up with another approach that's cleaner and more consistent.
Backwards Compatibility
It's a breaking change.
Copyright
Copyright and related rights waived via CC0
The text was updated successfully, but these errors were encountered: