[Issue 5399] Return the result of a nonvoid function in a void function

2011-10-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5399


Walter Bright bugzi...@digitalmars.com changed:

   What|Removed |Added

 Status|REOPENED|RESOLVED
 Resolution||FIXED
   Severity|major   |enhancement


--- Comment #11 from Walter Bright bugzi...@digitalmars.com 2011-10-09 
14:54:12 PDT ---
https://github.com/D-Programming-Language/dmd/commit/c942d51c8b1103d5ce4c3dfc03ae77c07c687cd6

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


[Issue 5399] Return the result of a nonvoid function in a void function

2011-06-29 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5399


yebblies yebbl...@gmail.com changed:

   What|Removed |Added

 CC||yebbl...@gmail.com


--- Comment #8 from yebblies yebbl...@gmail.com 2011-06-29 18:58:29 EST ---
I'll copy what I said in issue 3746:

Without this feature, what should happen with lazy void?

void lazyFunc(lazy void a) { a; }

void main()
{
   int i;
   lazyFunc(i++);
}

lazyFunc(i++) is currently re-written to something like
lazyFunc({return i++;})
This of course is broken if returning a non-void from a void function is
disallowed.

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


[Issue 5399] Return the result of a nonvoid function in a void function

2011-06-29 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5399


Don clugd...@yahoo.com.au changed:

   What|Removed |Added

 CC||clugd...@yahoo.com.au


--- Comment #9 from Don clugd...@yahoo.com.au 2011-06-29 02:29:05 PDT ---
(In reply to comment #8)
 I'll copy what I said in issue 3746:
 
 Without this feature, what should happen with lazy void?
 
 void lazyFunc(lazy void a) { a; }
 
 void main()
 {
int i;
lazyFunc(i++);
 }
 
 lazyFunc(i++) is currently re-written to something like
 lazyFunc({return i++;})
 This of course is broken if returning a non-void from a void function is
 disallowed.

What's wrong with
lazyFunc( { i++; return;})
?

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


[Issue 5399] Return the result of a nonvoid function in a void function

2011-06-29 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5399


yebblies yebbl...@gmail.com changed:

   What|Removed |Added

   Keywords||patch


--- Comment #10 from yebblies yebbl...@gmail.com 2011-06-30 03:02:12 EST ---
(In reply to comment #9)
 What's wrong with
 lazyFunc( { i++; return;})
 ?

For some reason I was thinking this would skip the 'expression has no effect'
errors.

https://github.com/D-Programming-Language/dmd/pull/174

Fixing this found a bug in phobos.

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


[Issue 5399] Return the result of a nonvoid function in a void function

2011-01-02 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5399


nfx...@gmail.com changed:

   What|Removed |Added

 CC||nfx...@gmail.com


--- Comment #3 from nfx...@gmail.com 2011-01-02 05:45:57 PST ---
(In reply to comment #2)
 It is not a dangerous corner case, it is a deliberate design choice. It is
 meant to facilitate writing generic code so that the same code can be 
 generated
 for void and non-void return values.

Wow, D is really full of idiocy, isn't it?

If you wanted to facilitate that, you'd just allow declaring void variables and
all that. I've written generic code where _that_ would have been quite useful.
But returning non-void values in void functions? Garbage language feature.

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


[Issue 5399] Return the result of a nonvoid function in a void function

2011-01-02 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5399


Iain Buclaw ibuc...@ubuntu.com changed:

   What|Removed |Added

 CC||ibuc...@ubuntu.com


--- Comment #4 from Iain Buclaw ibuc...@ubuntu.com 2011-01-02 06:24:38 PST ---
(In reply to comment #2)
 It is not a dangerous corner case, it is a deliberate design choice. It is
 meant to facilitate writing generic code so that the same code can be 
 generated
 for void and non-void return values.

Just for clarification, so you allow this, but the return value is always
ignored? (ie: 0)

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


[Issue 5399] Return the result of a nonvoid function in a void function

2011-01-02 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5399


Andrei Alexandrescu and...@metalanguage.com changed:

   What|Removed |Added

   Priority|P2  |P5
 Status|RESOLVED|REOPENED
 CC||and...@metalanguage.com
 Resolution|INVALID |
   Severity|enhancement |major


--- Comment #5 from Andrei Alexandrescu and...@metalanguage.com 2011-01-02 
06:48:17 PST ---
This is a very problematic misfeature that takes no effort to remove. In
particular I confirm it is of no or negative use to generic programming.
Walter, please let's remove it in the next release. Thank you.

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


[Issue 5399] Return the result of a nonvoid function in a void function

2011-01-02 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5399



--- Comment #6 from nfx...@gmail.com 2011-01-02 07:46:29 PST ---
I think the issue is with allowing stuff like this:

Result wrapCall(alias call, Result, Args...)(Args args) {
   return call(args);
}

And then making it work even if the result of the call is void:

wrapCall(something, void, int, int)(1, 2);

That requires that you can return a void value. Returning a void normally
wouldn't make sense, but as you can see it simplifies generic programming.

Somehow it made sense in Walter's head to allow returning _anything_ from a
void function. (It would make sense if void would work like Scala's Unit, but
void doesn't.)

Walter, please explain.

By the way if D were really orthogonal and would follow any logic, you wouldn't
have any problem with this code:

Result wrapCall(alias call, Result, Args...)(Args args) {
   try {
  return call(args);
   } catch {
  writefln(call failed!);
  return Result.init;
   }
}

This works, except when Result is void. Then you have to use static if,
duplicate the core code around the actual call if that is more complicated than
in the given example, and so on. (I had this in real world code.)

Sure makes a lot of sense.

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


[Issue 5399] Return the result of a nonvoid function in a void function

2011-01-02 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5399



--- Comment #7 from Andrei Alexandrescu and...@metalanguage.com 2011-01-02 
09:05:29 PST ---
(In reply to comment #6)
 I think the issue is with allowing stuff like this:
 
 Result wrapCall(alias call, Result, Args...)(Args args) {
return call(args);
 }
 
 And then making it work even if the result of the call is void:
 
 wrapCall(something, void, int, int)(1, 2);
 
 That requires that you can return a void value. Returning a void normally
 wouldn't make sense, but as you can see it simplifies generic programming.

Yes, that's a classic in C++ too. My assessment refers not to forwarding across
void function, but to void functions returning non-void expressions.

To clarify: forwarding from one void function to another void function is
useful. Having a void function return a non-void value should be removed.

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


[Issue 5399] Return the result of a nonvoid function in a void function

2011-01-01 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5399


bearophile_h...@eml.cc changed:

   What|Removed |Added

   Severity|normal  |enhancement


--- Comment #1 from bearophile_h...@eml.cc 2011-01-01 23:00:02 PST ---
This isn't a bug, I was wrong. D2 specs clearly show this is working as
expected:
http://www.digitalmars.com/d/2.0/statement.html

ReturnStatement:
return;
return Expression ;

Expression is allowed even if the function specifies a void return type. The
Expression will be evaluated, but nothing will be returned. If the Expression
has no side effects, and the return type is void, then it is illegal.


Indeed, this too compiles:

void main() {
int x;
return x++;
}


But this is a potentially dangerous corner case in the return rules.

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


[Issue 5399] Return the result of a nonvoid function in a void function

2011-01-01 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5399


Walter Bright bugzi...@digitalmars.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||bugzi...@digitalmars.com
 Resolution||INVALID


--- Comment #2 from Walter Bright bugzi...@digitalmars.com 2011-01-01 
23:33:12 PST ---
It is not a dangerous corner case, it is a deliberate design choice. It is
meant to facilitate writing generic code so that the same code can be generated
for void and non-void return values.

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