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



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



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




12:12:00 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.
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



*** 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



*** 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



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



*** 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




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



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





 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





 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






 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





 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




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



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