www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Big bug with scope() in nested { }

reply BCS <nowher spamdrop.uidaho.edu> writes:
This *is* a bug. Has it been reported yet?

<code>
import std.stdio;

void main()
{
	{
		scope(exit) writef("a\n");
	}

	scope(exit) writef("b\n");
}
<code>

output:

a
b
b
Sep 23 2006
next sibling parent BCS <nowhere pamdump.uidaho.edu> writes:
forgot to mention

DMD 0.164 linux
Sep 23 2006
prev sibling parent reply Mikola Lysenko <mclysenk mtu.edu> writes:
BCS wrote:
 This *is* a bug. Has it been reported yet?
 
 <code>
 import std.stdio;
 
 void main()
 {
 	{
 		scope(exit) writef("a\n");
 	}
 
 	scope(exit) writef("b\n");
 }
 <code>
 
 output:
 
 a
 b
 b

Probably a new discovery. This is related to the try-catch bug that has been around since DMD 0.150. So far, no fix. Here are the relevant posts: http://lists.puremagic.com/pipermail/digitalmars-d-bugs/2006-May/000854.html http://lists.puremagic.com/pipermail/digitalmars-d-bugs/2006-August/001911.html Hopefully they will get fixed soon.
Sep 24 2006
parent reply BCS <nowhere spamdump.uidaho.edu> writes:
== Quote from Mikola Lysenko (mclysenk mtu.edu)'s article
 Probably a new discovery.  This is related to the try-catch bug that
 has been around since DMD 0.150.  So far, no fix.  Here are the
 relevant posts:

http://lists.puremagic.com/pipermail/digitalmars-d-bugs/2006-May/000854.html

http://lists.puremagic.com/pipermail/digitalmars-d-bugs/2006-August/001911.html
 Hopefully they will get fixed soon.

Likely this is related, but both of them only mention cases where delegates are used, How does mine create a delegate? (From the scope statement?) OTOH is this bug known to cause problems elsewhere? (I didn't read then whole thread)
Sep 24 2006
parent Mikola Lysenko <mclysenk mtu.edu> writes:
BCS wrote:
 Likely this is related, but both of them only mention cases where delegates are
 used, How does mine create a delegate? (From the scope statement?) OTOH is this
 bug known to cause problems elsewhere? (I didn't read then whole thread)
 

From what I've worked out, it appears to be an issue with the way the compiler calculates offsets for things like catch and finally blocks in general. The delegates are just one case of this bug. Whenever there is more than one set of scope exit blocks, the bug will manifest. It appears to be because the compiler does not properly compute the offsets in one of the DHandler structs (though the exact details escape me at the moment, since it has been a few months since I spent any time wrestling with this problem.) It is a rather aggravating problem, which took me several hours of single stepping through the asm from deh2.d to figure out what was going. I certainly hope it gets fixed in the next release.
Sep 25 2006