I want this so badly, please implement

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 7 08:59:31 PDT 2016


On Thursday, 7 April 2016 at 07:07:32 UTC, Nordlöw wrote:
> Could you please add a test-program with current and wanted 
> behaviour?

int[] a = new int[](1);
a[2]; // currently throws RangeError, telling file and line of 
code


I'd like it to throw a RangeError telling file and line of code, 
and idx == 2, length == 1.


The way it works is the compiler, in e2ir.c (unless I'm mistaken) 
turns the index and slice expressions into code. It basically 
generates this code:

((idx < length) || _d_array_bounds(module*, cast(uint) 
line_number)), array.ptr[idx]


What I want it to do is generate this code:


((idx < length) || _d_array_bounds(module*, cast(uint) 
line_number), idx, length), array.ptr[idx]


Just so idx and length is passed to the druntime function.

That's dmd's change. Make sure it covers all the places the array 
bounds functions are called.

(I thought this would be easy but I keep hitting dmd assert 
failures. However, that's probably because I'm a n00b, it 
probably is easy if you know the e2ir style.)

Then, on the druntime side, change the function to accept the 
size_t idx, size_t length in addition to its current args.

Forward them through to the RangeError object (or a subclass), 
which then prints them too.



More information about the Digitalmars-d mailing list