www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7210] New: opCall weird behavior in struct

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: szadows gmail.com



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: -------
Jan 03 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7210


Gašper Ažman <gasper.azman gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |gasper.azman gmail.com



PDT ---
This is more about opCall not working for structs whenever a constructor is
present. For instance, this works:

import std.stdio;

struct B {
    int number;
    string word;

    static B opCall(int n) {
        B b = {n, ""};
        return b;
    }
    string opCall(string w)
    {
        word = w;
        return word;
    }
}

void main() {
    auto b = B(3);
    writeln(b("Hello World"));
}

but this doesn't:



import std.stdio;

struct A {
    int number;
    string word;
    this(int n) {
        number = n;
        word = "";
    }
    string opCall(string w)
    {
        word = w;
        return word;
    }
}

int main() {
    auto a = A(3);
    writeln(a("Hello World"));
}

atom kamichan $ dmd test.d 
test.d(20): Error: constructor test.A.this (int n) is not callable using
argument types (string)
test.d(20): Error: cannot implicitly convert expression ("Hello World") of type
string to int
test.d(18): Error: function D main has no return statement, but is expected to
return a value of type int
atom kamichan $ dmd
DMD64 D Compiler v2.059

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


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



10:49:44 PDT ---
*** Issue 8677 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: -------
Sep 17 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7210


bearophile_hugs eml.cc changed:

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



Seems fixed. See Issue 6036

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 06 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7210


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



*** This issue has been marked as a duplicate of issue 6036 ***

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