www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - WTF does "Enforcement failed" actually mean?

reply Russel Winder via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
I have the code:

	reduce!"a+b"(x)

where x is a int[] and I get an exception "Enforcement failed" at run
time. This gives me enough information to say =C2=BFque?

--=20
Russel.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder ekiga.n=
et
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
Sep 30 2015
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 09/30/2015 10:46 PM, Russel Winder via Digitalmars-d-learn wrote:
 I have the code:

 	reduce!"a+b"(x)

 where x is a int[] and I get an exception "Enforcement failed" at run
 time. This gives me enough information to say ¿que?
It's coming from the following no-message enforce(): enforce(!r.empty); https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm/iteration.d#L2481 You are using the no-seed version of reduce(), which uses the first element as seed, which means that the range cannot be empty. Ali
Sep 30 2015
parent reply Russel Winder via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Wed, 2015-09-30 at 23:35 -0700, Ali =C3=87ehreli via Digitalmars-d-learn
wrote:
 On 09/30/2015 10:46 PM, Russel Winder via Digitalmars-d-learn wrote:
 I have the code:
=20
 	reduce!"a+b"(x)
=20
 where x is a int[] and I get an exception "Enforcement failed" at
 run
 time. This gives me enough information to say =C2=BFque?
=20
=20 It's coming from the following no-message enforce(): =20 enforce(!r.empty); =20 =20 https://github.com/D-Programming-Language/phobos/blob/master/std/algo rithm/iteration.d#L2481 =20 You are using the no-seed version of reduce(), which uses the first=20 element as seed, which means that the range cannot be empty.
Well that explanation (*) makes it abundantly clear that the error reporting from this part of Phobos is distinctly substandard, let alone below par. (*) Which is clear and informative! --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Oct 01 2015
parent reply John Colvin <john.loughran.colvin gmail.com> writes:
On Thursday, 1 October 2015 at 07:08:00 UTC, Russel Winder wrote:
 On Wed, 2015-09-30 at 23:35 -0700, Ali Çehreli via 
 Digitalmars-d-learn wrote:
 On 09/30/2015 10:46 PM, Russel Winder via Digitalmars-d-learn 
 wrote:
 [...]
It's coming from the following no-message enforce(): enforce(!r.empty); https://github.com/D-Programming-Language/phobos/blob/master/std/algo rithm/iteration.d#L2481 You are using the no-seed version of reduce(), which uses the first element as seed, which means that the range cannot be empty.
Well that explanation (*) makes it abundantly clear that the error reporting from this part of Phobos is distinctly substandard, let alone below par. (*) Which is clear and informative!
Bug report? Then it'll get fixed.
Oct 01 2015
next sibling parent Marco Leise <Marco.Leise gmx.de> writes:
Am Thu, 01 Oct 2015 08:52:43 +0000
schrieb John Colvin <john.loughran.colvin gmail.com>:

 On Thursday, 1 October 2015 at 07:08:00 UTC, Russel Winder wrote:
 On Wed, 2015-09-30 at 23:35 -0700, Ali =C3=87ehreli via=20
 Digitalmars-d-learn wrote:
 On 09/30/2015 10:46 PM, Russel Winder via Digitalmars-d-learn=20
 wrote:
 [...]
=20 It's coming from the following no-message enforce(): =20 enforce(!r.empty); =20 =20 https://github.com/D-Programming-Language/phobos/blob/master/std/algo rithm/iteration.d#L2481 =20 You are using the no-seed version of reduce(), which uses the=20 first element as seed, which means that the range cannot be=20 empty.
Well that explanation (*) makes it abundantly clear that the=20 error reporting from this part of Phobos is distinctly=20 substandard, let alone below par. (*) Which is clear and informative!
=20 Bug report? Then it'll get fixed.
The problem is that in out minds addition has an implicit seed value of 0 and multiplication has 1, so a potentially empty range doesn't immediately raise a red flag. The correct thing to use, following this train of thought, is http://dlang.org/phobos/std_algorithm_iteration.html#.sum (Additionally it provides better accuracy when summing up floating-point values.) --=20 Marco
Oct 01 2015
prev sibling parent Russel Winder via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Thu, 2015-10-01 at 08:52 +0000, John Colvin via Digitalmars-d-learn
wrote:
 [=E2=80=A6]
=20
 Bug report? Then it'll get fixed.
https://issues.dlang.org/show_bug.cgi?id=3D15133 Timer running=E2=80=A6 ;-) --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Oct 01 2015