[Issue 4053] New: To avoid struct ctor/opCall conflicts

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Apr 2 17:03:44 PDT 2010


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

           Summary: To avoid struct ctor/opCall conflicts
           Product: D
           Version: future
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2010-04-02 17:03:42 PDT ---
This is a D2 program:


struct Foo {
    this(int x=0) {}
    static void opCall(int x, int y) {}
}
void main() {
    auto f2 = Foo(1);    // line 6, OK
    auto f3 = Foo(1, 2); // line 7, Err, opCall not found
    auto f1 = Foo();     // line 8, Err, conflicts with opCall again
}


dmd 2.042 gives:

test.d(7): Error: constructor test.Foo.this (int x = 0) is not callable using
argument types (int,int)
test.d(7): Error: expected 1 arguments, not 2 for non-variadic function type
ref Foo(int x = 0)
test.d(8): Error: function test.Foo.opCall (int x, int y) is not callable using
argument types ()
test.d(8): Error: expected 2 function arguments, not 0
test.d(8): Error: variable test.main.f1 voids have no value
test.d(8): Error: expression opCall() is void and has no value


My suggestion is in structs to disallow opCall() if a this() is present.
This makes the program more tidy, and avoids that conflict with opCall when
Foo() is used with no arguments.

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