Bug 364 – Mysterious access violation when using delegate()[1]... parameter

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-09-23T16:44:00Z
Last change time
2014-02-15T13:20:10Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
smjg

Comments

Comment #0 by smjg — 2006-09-23T16:44:01Z
One case of delegate parameters used for lazy evaluation of expressions has been kept, namely typesafe variadic parameters. However, the following use causes an access violation to be thrown for no apparent reason. ---------- import std.stdio; abstract class Comb { Comb opCall(Comb delegate()[1] c...) { static int level = -1; level++; writefln("%*sCO: %s", level, "", this); Comb ec = c[0](); writefln("%*sCO: %s to %s", level, "", this, ec); Comb result = apply(ec); writefln("%*sCO: %s to %s, result: %s", level, "", this, ec, result); level--; return result; } abstract Comb apply(Comb c); } class SComb2 : Comb { Comb c1; Comb c2; this(Comb a1, Comb a2) { c1 = a1; c2 = a2; } Comb apply(Comb c) out (result) { writefln("SA: %s to %s, result: %s", this, c, result); } body { writefln("SA: %s to %s", this, c); return c1.apply(c)(c2(c)); } char[] toString() { return "S[" ~ c1.toString ~ ", " ~ c2.toString ~ "]"; } } class IComb : Comb { Comb apply(Comb c) { return c; } char[] toString() { return "I"; } } void main() { Comb I = new IComb; /* This represents the combinator expression * S I I I */ (new SComb2(I, I)) (I); } ---------- CO: S[I, I] CO: S[I, I] to I SA: S[I, I] to I CO: I CO: I CO: I to I CO: I to I, result: I CO: I to I CO: I to I, result: I SA: S[I, I] to I, result: I Error: Access Violation ---------- As you see, it happens between SComb2.apply returning and the next statement in Comb.opCall being executed. If the statement in main is changed to (new SComb2(I, I)).apply(I); then the same happens, except that (as expected) the first two lines above aren't printed. If I also add writefln("CO"); after the apply call in Comb.opCall, then the error message changes to the even more cryptic Error: Win32 Exception
Comment #1 by bugzilla — 2006-11-25T03:50:28Z
Fixed DMD 0.175