www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6417] New: Problem with count inside out{} of class method

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

           Summary: Problem with count inside out{} of class method
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



D2 code:


import core.stdc.stdio: printf;
import std.algorithm: count;
class Foo {
    void bar()
    out {
        int i = 10;
        count!((int k){ printf("%d\n", i); return 1; })([0]);
    } body {}
}
void main() {
    auto f = new Foo();
    f.bar();
}


It prints:
1244668

Instead of:
10

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


kennytm gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm gmail.com
           Platform|x86                         |All
            Summary|Problem with count inside   |Wrong context point for
                   |out{} of class method       |delegates inside contracts
                   |                            |of class member functions
         OS/Version|Windows                     |All



Reduced test case:

-------------------------------
//import core.stdc.stdio;
class Bug6417 {
    void bar()
    in {
        int i = 14;
        assert(i == 14);
        auto d = (){ 
            assert(i == 14, "in contract failure"); // <-- fail
        };
        //printf("%p %p\n", d.ptr, &this);
        d();
    }
    out {
        int i = 10;
        assert(i == 10);
        (){ 
            assert(i == 10, "out contract failure"); // <-- also fail
        }();
    }
    body {}
}
void main() {
    (new Bug6417).bar();
}
-------------------------------

When running, the "in contract failure" assertion will be thrown.

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




Created an attachment (id=1216)
test case for foreach-opApply

I'm also hit this by foreach-block using opApply-range.
The test case is attached.

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