study: use checkedint as a drop-in replacement of native long

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Aug 17 18:10:16 UTC 2020


On Mon, Aug 17, 2020 at 05:58:16PM +0000, mw via Digitalmars-d wrote:
> On Monday, 17 August 2020 at 17:15:59 UTC, H. S. Teoh wrote:
[...]
> > Chain assignment fix: https://github.com/dlang/phobos/pull/7599
> 
> Thanks for the PR, I just added comments: does this fix also work for
> mixed native & checked chain assignment? i.e. add to unittest:
> 
> ```
>   long la, lb;
>   Checked!long ca, cb;
> 
>   la = ca = lb = cb;  // mixed chain assign
>   ca = la = cb = lb;
> ```

Currently, it doesn't work.  I'm on the fence about whether it should:
the whole point of using Checked is that you don't want to automatically
convert to the native type because the converted value will lose the
protections conferred by Check.  Assigning a Checked to a native type
*might* be a mistake - you thought the variable was Checked but it
wasn't, so subsequent operations on it no longer has Checked semantics
even though you thought it does.  So I'm not sure this case should be
supported.  Assigning from Checked back to native should always be
explicit IMO (the programmer explicitly indicates he doesn't want
Checked protections anymore).


T

-- 
If I were two-faced, would I be wearing this one? -- Abraham Lincoln


More information about the Digitalmars-d mailing list