www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3746] New: Misleding error message "OP has no effect in expression XXX), in void function

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

           Summary: Misleding error message "OP  has no effect in
                    expression XXX), in void function
           Product: D
           Version: 2.041
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: baryluk smp.if.uj.edu.pl


--- Comment #0 from Witold Baryluk <baryluk smp.if.uj.edu.pl> 2010-01-27
17:15:05 PST ---
On function with void return type, if one will put expression after return:

void f() {
   auto a = 1, b = 3, c = 5;
   return a/b*c;
}


will end with compiler error like:

aaa.d(4): Error: * has no effect in expression (a / b * c)


My function "f" was lot bigger, and took me about 5 minutes to understand what
is wrong.

Could such bugs can be detected and be something like

aaa.d(4): Error: no return statment allowed in void function/method

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 27 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746


Witold Baryluk <baryluk smp.if.uj.edu.pl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 27 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746


Bernard Helyer <blood.of.life gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |blood.of.life gmail.com


--- Comment #1 from Bernard Helyer <blood.of.life gmail.com> 2010-01-27
19:59:24 PST ---
Well, obviously return *is* allowed from void functions (void f() { return; }).
But 'error: return statement with a value in a void function' would be a
preferable message than talking about values having no effect in expressions.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 27 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746



--- Comment #2 from Witold Baryluk <baryluk smp.if.uj.edu.pl> 2010-01-28
12:12:00 PST ---
(In reply to comment #1)
 Well, obviously return *is* allowed from void functions (void f() { return; }).
 But 'error: return statement with a value in a void function' would be a
 preferable message than talking about values having no effect in expressions.
Yes you are right. Error messages should be as precise as possible. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 28 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sky q1cc.net


--- Comment #3 from yebblies <yebblies gmail.com> 2011-06-12 23:18:47 PDT ---
*** Issue 3855 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 12 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |DUPLICATE


--- Comment #4 from yebblies <yebblies gmail.com> 2011-06-12 23:19:46 PDT ---
*** This issue has been marked as a duplicate of issue 3630 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 12 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|DUPLICATE                   |
           Severity|minor                       |enhancement


--- Comment #5 from yebblies <yebblies gmail.com> 2011-06-12 23:21:28 PDT ---
My bad, this is a request for a better error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 12 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746


bearophile_hugs eml.cc changed:

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


--- Comment #6 from bearophile_hugs eml.cc 2011-06-13 03:21:08 PDT ---
*** Issue 3922 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 13 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746



--- Comment #7 from bearophile_hugs eml.cc 2011-06-13 03:22:41 PDT ---
Issue 3922 contains some interesting comments.

It seems this enhancement request for a better error message has many dupes!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 13 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
            Summary|Misleding error message "OP |Misleading error message
                   | has no effect in           |"OP  has no effect in
                   |expression XXX), in void    |expression XXX), in void
                   |function                    |function


--- Comment #8 from yebblies <yebblies gmail.com> 2011-06-13 13:34:34 PDT ---
https://github.com/D-Programming-Language/dmd/pull/121

This adds the error message:
testx.d(4): Error: expression with no side effects used with void return

Good enough?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 13 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746



--- Comment #9 from bearophile_hugs eml.cc 2011-06-13 14:31:09 PDT ---
(In reply to comment #8)
 https://github.com/D-Programming-Language/dmd/pull/121
 
 This adds the error message:
 testx.d(4): Error: expression with no side effects used with void return
 
 Good enough?
I don't understand. Elsewhere I have a bug report that asks for a new error message if you don't use the result of a pure function. But this bug report just asks for a better error message in the situation of using "return x;" in a void function. So I expected an error message like: foo.d(20): Error: a void function can't return 'int'. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 13 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746



--- Comment #10 from yebblies <yebblies gmail.com> 2011-06-13 22:21:03 PDT ---
(In reply to comment #9)
 I don't understand. Elsewhere I have a bug report that asks for a new error
 message if you don't use the result of a pure function.
 But this bug report just asks for a better error message in the situation of
 using "return x;" in a void function. So I expected an error message like:
 
 foo.d(20): Error: a void function can't return 'int'.
Returning an int expression from a void function is perfectly legal, so long as the expression has side effects. This is explicitly allowed by the spec. http://www.digitalmars.com/d/2.0/statement.html#ReturnStatement You're talking about two completely separate issues, both of which are enhancements. This issue is about providing a clearer error message without changing the spec. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 13 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746



--- Comment #11 from bearophile_hugs eml.cc 2011-06-14 05:14:02 PDT ---
(In reply to comment #10)

 You're talking about two completely separate issues, both of which are
 enhancements.  This issue is about providing a clearer error message without
 changing the spec.
Walter has accepted one of the enhancement requests I was talking about (the one about pure functions). I was not aware the second too is an enhancement request, but after re-reading that part of the D specs I see you are right. So technically your error message is correct. But it's hard to keep in memory all the D specs, especially for D newbies. So I suggest a longer and more wordy error message, because this error message is not easy enough to understand. ---------- According to the D specs this code is illegal, is your patch raising an error on it? pure int sqr(int x) { return x * x; } void main() { return sqr(10); } ---------- According to the current D specs this code is correct: int sqr(int x) { return x * x; } void main() { return sqr(10); } But I can't see this as correct, it's bug prone. So bug 3922 was not a dupe, it was an ehancement request! I have to reopen it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 14 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au


--- Comment #12 from Don <clugdbug yahoo.com.au> 2011-06-14 05:19:10 PDT ---
(In reply to comment #10)
 (In reply to comment #9)
 I don't understand. Elsewhere I have a bug report that asks for a new error
 message if you don't use the result of a pure function.
 But this bug report just asks for a better error message in the situation of
 using "return x;" in a void function. So I expected an error message like:
 
 foo.d(20): Error: a void function can't return 'int'.
Returning an int expression from a void function is perfectly legal, so long as the expression has side effects. This is explicitly allowed by the spec. http://www.digitalmars.com/d/2.0/statement.html#ReturnStatement
Yes, but it was agreed on the newsgroup that this is a misfeature. (Andrei was horrified about it). It should be disallowed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 14 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746



--- Comment #13 from yebblies <yebblies gmail.com> 2011-06-14 08:51:36 PDT ---
Without this feature, what should happen with lazy void?

void lf(lazy void a) { a; }

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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 14 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3746


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #14 from yebblies <yebblies gmail.com> 2011-10-10 13:22:15 EST ---
This bug has been fixed with issue 5399.

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: -------
Oct 09 2011