[Issue 9110] Lazy variadic array error message is confusing

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue May 26 07:00:03 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=9110

Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at yahoo.com
           Hardware|x86_64                      |All
            Summary|Escaping reference error    |Lazy variadic array error
                   |from lazy variadic          |message is confusing
                   |parameters                  |
                 OS|Linux                       |All

--- Comment #3 from Steven Schveighoffer <schveiguy at yahoo.com> ---
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".

--


More information about the Digitalmars-d-bugs mailing list