Unexpected range assignment behaviour

H. S. Teoh hsteoh at qfbox.info
Fri Jul 19 18:02:55 UTC 2024


On Fri, Jul 19, 2024 at 05:48:37PM +0000, Dennis via Digitalmars-d-learn wrote:
> On Friday, 19 July 2024 at 17:20:22 UTC, matheus wrote:
> > couldn't this case for example be caught during the compiling time?
> 
> The RangeError is only thrown when at runtime, the key doesn't exist,
> so that can't be caught. The real problem is implicit slicing of
> static arrays, which I'm not a fan of, but removing it is a breaking
> change. So perhaps Associative Arrays should be enhanced to create
> keys on slice assignment.

IMO, implicit slicing of static arrays ought to be killed with fire.
This is not the first time it has caused problems.  In the past it used
to cause issues with the implicit slice escaping the scope of the
original static array, leading to dangling pointers and subsequent
memory corruption / UB.  With -dip1000 the situation has somewhat
improved, but not entirely. It still causes nasty surprises when a slice
was implicitly taken where it was unexpected.  This case here is another
example of the problems that it causes.


T

-- 
I don't trust computers, I've spent too long programming to think that
they can get anything right. -- James Miller


More information about the Digitalmars-d-learn mailing list