www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3667] New: broken out(result) in contracts

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

           Summary: broken out(result) in contracts
           Product: D
           Version: 2.038
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: netrino inbox.ru


--- Comment #0 from Ludwig <netrino inbox.ru> 2010-01-03 11:33:25 PST ---
Regression bug since 2.037. For example in such code:

import std.stdio;

int mul100(int n)
out(result)
{
    writeln("result == ", result);
}
body
{
    return n * 100;
}

int main()
{
    mul100(5);
    return 0;
}

compiled with -debug output is always
result == 0 and should be result == 500

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


Luther Tychonievich <lat7h virginia.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lat7h virginia.edu


--- Comment #1 from Luther Tychonievich <lat7h virginia.edu> 2010-01-12
13:09:11 PST ---
More details: for any primitive type (all integer, character, and floating
point types, including unsigned, complex, and typedef'd varieties thereof) the
out contract's result will always be type.init.  For example, the following
code works (and shouldn't, the out contract is incorrect):
-------
typedef cdouble sometype = 4.0 + 2.0i;

sometype buggy() 
  out(result) { assert( result == 4.0 + 2.0i ); } // should fail but doesn't
  body        { return cast(sometype)0;  }

unittest { assert(buggy() == 0); }
-------

This does not happen for structs, classes, static or dynamic arrays (all seem
to function correctly).

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


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei metalanguage.com


--- Comment #2 from Andrei Alexandrescu <andrei metalanguage.com> 2010-02-21
17:01:52 PST ---
An example involving a nested function:

void fun() {
    int gun()
        out(result)
    {
        assert(result == 42);
    } body
    {
        return 42;
    }

    gun();
}

void main() {
    fun();
}

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |baryluk smp.if.uj.edu.pl


--- Comment #3 from Witold Baryluk <baryluk smp.if.uj.edu.pl> 2010-03-09
17:08:03 PST ---
It is probably related to bug3634

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


Don <clugdbug yahoo.com.au> changed:

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


--- Comment #4 from Don <clugdbug yahoo.com.au> 2010-03-15 00:55:50 PDT ---
*** Issue 3963 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: -------
Mar 15 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3667



--- Comment #5 from Luther Tychonievich <lat7h virginia.edu> 2010-03-15
20:43:30 PDT ---
Not sure if it helps, but the compiler knows this problem will arise at compile
time; the following compiles just fine, though it clearly should not:
-----
int buggy(int y)
out(result) { static assert(result==0); }
body        { return y; }
void main() { buggy(3); }
----
I don't know why.  Debugging shows that statement.c:3490 still creates the
"result = y" assignment I'd expect... I don't know where else to look.

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



--- Comment #6 from Shin Fujishiro <rsinfu gmail.com> 2010-05-07 11:30:35 PDT
---
Created an attachment (id=624)
Patch for DMD 2.045

The attached patch should fix the problem.

Since DMD 2.028, result variables are marked as const.  The cause of this bug
is that DMD mistakenly tries to const-fold a result variable into its default
initializer.  Unfortunately, it succeeds when return type is a basic value type
(int, bool, etc.).

The attached patch adds a STCresult storage class to declaration.h, and applies
it to the vresult.  The STCresult is similar to the STCparameter; it disables
default-value initialization of result variables.

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


Walter Bright <bugzilla digitalmars.com> changed:

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


--- Comment #7 from Walter Bright <bugzilla digitalmars.com> 2010-05-15
16:17:46 PDT ---
changelog 490

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



--- Comment #8 from Don <clugdbug yahoo.com.au> 2010-06-07 00:11:57 PDT ---
*** Issue 3634 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 07 2010