Thread overview
[Issue 9423] New: Missed conversion of lambda literal with ref argument
Jan 29, 2013
Kenji Hara
January 29, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9423

           Summary: Missed conversion of lambda literal with ref argument
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2013-01-29 02:51:30 PST ---
void foo(int delegate(ref int[1]) spam) {}
void main() {
    foo((ref int[1] x) => 0); // OK
    foo(x => 0); // Error
}



DMD 2.062alpha gives:

test.d(4): Error: function test.foo (int delegate(ref int[1u]) spam)(null) is
not callable using argument types (void)
test.d(4): Error: cannot implicitly convert expression (__lambda3) of type int
delegate(int[1u] x) pure nothrow @safe to int delegate(ref int[1u])

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 29, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9423


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
           Platform|x86                         |All
         OS/Version|Windows                     |All
           Severity|normal                      |enhancement


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2013-01-29 09:23:54 PST ---
When I fixed bug7705, I decided that lambda inference does not infer parameter storage classes. Instead, users should specify `ref`/`out`/`lazy` explicitly.

https://github.com/D-Programming-Language/dmd/pull/809/files#L1R496

Because, explicit specifying of `ref` in call site is sometimes required in newsgroup.

void foo(ref int x) {}
int n;
foo(ref n);   // not allowed in today

So, current behavior is intended. You should write it as follows:

void foo(int delegate(ref int[1]) spam) {}
void main() {
    foo((ref x) => 0); // OK
}

However, I cannot say clearly whether it's right behavior.
I think that the opinion "parameter storage classes should be inferred" is also
worth.

Therefore, I'll mark this as 'enhancement'.

=====

A pull to implement this feature: https://github.com/D-Programming-Language/dmd/pull/1580

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 29, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9423



--- Comment #2 from bearophile_hugs@eml.cc 2013-01-29 10:00:15 PST ---
(In reply to comment #1)

> Therefore, I'll mark this as 'enhancement'.
> 
> =====
> 
> A pull to implement this feature: https://github.com/D-Programming-Language/dmd/pull/1580

Thank you Hara.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 30, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9423



--- Comment #3 from bearophile_hugs@eml.cc 2013-01-30 10:26:15 PST ---
A discussion thread, the answers are mixed:

http://forum.dlang.org/thread/mixmakdqfmaznmmnizux@forum.dlang.org


A comment from Timon Gehr:

> BTW, the pull does not contain a test for the case
> 
> void foo(int delegate(int) dg){ ... }     // 1
> void foo(int delegate(ref int) dg){ ... } // 2
> 
> void main(){ foo(x=>0); } // call 1

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------