Bug 9110 – Lazy variadic array error message is confusing

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-02T17:30:53Z
Last change time
2024-12-13T18:03:06Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Roy Crihfield
Moved to GitHub: dmd#18500 →

Comments

Comment #0 by rscrihf — 2012-12-02T17:30:53Z
void main() { auto a = foo(); } int foo(lazy int[] dgs...) { int res; foreach (i, dg; dgs) res += dg; return res; } On 2.060, Fails with: Error: escaping reference to local __arrayArg1013 Fails with any number of arguments passed.
Comment #1 by monkeyworks12 — 2015-02-12T05:04:03Z
I've also just ran into this error. void test(lazy string[] s...) { } void main(string[] argv) { //Error: escaping reference to local test("asdf", "fdsa", "afsd", "sdaf"); }
Comment #2 by joeyemmons — 2015-05-26T05:05:59Z
Have also hit this... void main(string[] args) { test(a()); } bool a() { return true; } void test(lazy bool[] c...) { }
Comment #3 by schveiguy — 2015-05-26T14:00:03Z
This bug is invalid. What is happening is this: 1. Because the parameter is a typesafe variadic, the compiler pushes all the data onto the stack. 2. Because the parameter is lazy, instead of passing the data to the function, it creates a delegate to return the typesafe array. In actuality, the data is created inside the delegate. The constructed delegate is the one being flagged for returning a reference to the stack. If you imagine, the delegate looks like this: int[] implicitDelegate() { int[N] arr = [args_to_foo]; return arr[]; // this is the line that is causing the failure. } The correct way to do lazy variadic functions is this: int foo(int delegate()[] dgs...) I'm not going to close this, however. I'm going to repurpose it to change the error message. There is no possible way that the OP's code will or should compile. But the error message is very bad. I'd like to see it say something like: "lazy variadic array parameters are not allowed. Please use a variadic array of delegates".
Comment #4 by robert.schadek — 2024-12-13T18:03:06Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18500 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB