[Issue 7210] New: opCall weird behavior in struct

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 3 10:29:57 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7210

           Summary: opCall weird behavior in struct
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: szadows at gmail.com


--- Comment #0 from Robik <szadows at gmail.com> 2012-01-03 10:29:52 PST ---
I've been working on my project and expected weird behavior when using opCall
with structs. I've made a simple test case to demonstrate it. Following code
compiles on DMD 2.057:

    import std.stdio;
    import std.stdio;

    void main()
    {
        auto test = Test("");
        auto nested = Test("1");

        nested.tests ~= Test("2");
        test.tests ~= nested;

        writeln(test.get("1"));
        writeln(test.opCall("1"));
        writeln(test("1"));
    }

    struct Test
    {
        Test[] tests;
        string str;

        public this(string str)
        {
            this.str = str;
        }
        public ref Test get(string str)
        {
            return tests[0]; 
        }
        alias get opCall;
    }

Current result:

    Test([Test([], "2")], "1")
    Test([Test([], "2")], "1")
    Test([], "1")

Expected result:

    Test([Test([], "2")], "1")
    Test([Test([], "2")], "1")
    Test([Test([], "2")], "1")

As you may see, `test.opCall` works correct, when `test()` is not.

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


More information about the Digitalmars-d-bugs mailing list