www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8589] New: Incorrect conversion of function returning `typeof(null)` to function returning an array

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8589

           Summary: Incorrect conversion of function returning
                    `typeof(null)` to function returning an array
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2012-08-26
13:56:44 MSD ---
---
void f(int[] function() del)
{
    assert(!del());
}

typeof(null) g() { return null; }

void main()
{
    f(&g);
    f(() => null);
}
---
As a result `f(() => null)` will trigger this issue too. This makes lambda
expressions returning null very dangerous.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 26 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8589


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #1 from bearophile_hugs eml.cc 2012-08-26 04:38:12 PDT ---
This compiles:
f(() => null);


This causes no assert to fire:
foo(() => (int[]).init);


While this doesn't even compile:
foo(() => []);

Error: function test.foo (int[] function() del) is not callable using argument
types (void[] function() pure nothrow  safe)


See also Issue 7007


Since lot of time in D dynamic arrays are not pointers, so generally accepting
"null" as empty array literal is a wrong design decision, especially since the
"[]" literal is available.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 26 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8589


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2012-09-16 04:06:36 PDT ---
https://github.com/D-Programming-Language/dmd/pull/1119

Runtime representation of typeof(null) is same as void*, then delegate and
dynamic array type should not be covariant with typeof(null). It's limitation.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 16 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8589



--- Comment #3 from github-bugzilla puremagic.com 2013-03-06 14:28:14 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/043d6926ef4f3d0e8f25c1f0d69891bf7f39bdd1
fix Issue 8589 - Incorrect conversion of function returning `typeof(null)` to
function returning an array

https://github.com/D-Programming-Language/dmd/commit/f2b02836d7680aa3d1c92f2541c98638dcb0f0f9
Merge pull request #1119 from 9rnsr/fix8589

Issue 8589 - Incorrect conversion of function returning `typeof(null)` to
function returning an array

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 06 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8589


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 06 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8589


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #4 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-03-10
16:36:13 PDT ---
Kenji, is this a parser bug?

f(() => int[].init);

test.d(11): Error: found '[' when expecting '.' following int
test.d(11): Error: found ']' when expecting identifier following 'int.'

You have to use:

f(() => (int[]).init);

But that's not very convenient.

Also this won't work because '[]' will be typed as 'void[]':

f(() => []);

But I guess we'll have to live with that for now..

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8589



--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2013-03-10 20:55:04 PDT ---
(In reply to comment #4)
 Kenji, is this a parser bug?
 
 f(() => int[].init);
 
 test.d(11): Error: found '[' when expecting '.' following int
 test.d(11): Error: found ']' when expecting identifier following 'int.'
 
 You have to use:
 
 f(() => (int[]).init);
 
 But that's not very convenient.

No, it is not allowed in current grammar. So it is not a bug, but a limitation.
 Also this won't work because '[]' will be typed as 'void[]':

That would be a type inference bug. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 10 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8589



--- Comment #6 from Kenji Hara <k.hara.pg gmail.com> 2013-03-10 21:02:31 PDT ---
(In reply to comment #5)
 Also this won't work because '[]' will be typed as 'void[]':

That would be a type inference bug.

Oh.. sorry, it is a today's limitation, not a bug. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 10 2013