www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Typedef broken

reply "Kris" <fu bar.com> writes:
Given two almost identical classes:

==================

typedef uint Style;
const Style A = 1;

class C
{
        this (int i, Style s = A)
       {
            this (i, s);  // no conflict
        }
        this (int i, Style s = A) {}
        this (int i, uint j = 0, Style a = A) {}
}


class D
{
        this (int i, Style s = A)
        {
              this (new ubyte[i], s);  // conflict!
        }

        this (void[] d, Style s = A) {}
        this (void[] d, uint j = 0, Style a = A) {}
}

void main()
{
    new C(1);
    new D(2);
}

===================

Note that the only difference is that the first argument of the 2nd and 3rd 
ctors are int vs void[]. With class D, the compiler suddenly gets all 
confused over whether Style is a typedef or not. 
Dec 07 2005
parent reply "Walter Bright" <newshound digitalmars.com> writes:
"Kris" <fu bar.com> wrote in message news:dn8fb6$ip9$1 digitaldaemon.com...
 Given two almost identical classes:

 ==================

 typedef uint Style;
 const Style A = 1;

 class C
 {
         this (int i, Style s = A)
        {
             this (i, s);  // no conflict
         }
         this (int i, Style s = A) {}
         this (int i, uint j = 0, Style a = A) {}
 }


 class D
 {
         this (int i, Style s = A)
         {
               this (new ubyte[i], s);  // conflict!
         }

         this (void[] d, Style s = A) {}
         this (void[] d, uint j = 0, Style a = A) {}
 }

 void main()
 {
     new C(1);
     new D(2);
 }

 ===================

 Note that the only difference is that the first argument of the 2nd and
3rd
 ctors are int vs void[]. With class D, the compiler suddenly gets all
 confused over whether Style is a typedef or not.
When I compile it, I get: ----------------------------------- test.d(8): constructor test.C.this called with argument types: (int,Style) matches both: test.C.this(int,Style) and: test.C.this(int,Style) ------------------------------------ This error is correctly diagnosed. You have two constructors with the same type signature. --------------------------------- test.d(8): cyclic constructor call --------------------------------- This error is also correctly diagnosed. -------------------------------------------------------- test.d(19): constructor test.D.this called with argument types: (ubyte[],Style) matches both: test.D.this(void[],Style) and: test.D.this(void[],uint,Style) -------------------------------------------------------------- This error is correctly diagnosed, as both matches are with implicit conversions. ---------------------------------------------------- test.d(28): constructor test.C.this called with argument types: (int) matches both: test.C.this(int,Style) and: test.C.this(int,uint,Style) ------------------------------------------------ This error is correctly diagnosed. It's ambiguous.
Dec 10 2005
parent "Kris" <fu bar.com> writes:
Ack!

You're right, and the example is bogus. I cut & pasted from a much larger 
class, and made a hash of it. Will provide a better test-case tomorrow when 
I'm not so washed out.

- Kris


"Walter Bright" <newshound digitalmars.com> wrote in message 
news:dne6to$46s$1 digitaldaemon.com...
 "Kris" <fu bar.com> wrote in message 
 news:dn8fb6$ip9$1 digitaldaemon.com...
 Given two almost identical classes:

 ==================

 typedef uint Style;
 const Style A = 1;

 class C
 {
         this (int i, Style s = A)
        {
             this (i, s);  // no conflict
         }
         this (int i, Style s = A) {}
         this (int i, uint j = 0, Style a = A) {}
 }


 class D
 {
         this (int i, Style s = A)
         {
               this (new ubyte[i], s);  // conflict!
         }

         this (void[] d, Style s = A) {}
         this (void[] d, uint j = 0, Style a = A) {}
 }

 void main()
 {
     new C(1);
     new D(2);
 }

 ===================

 Note that the only difference is that the first argument of the 2nd and
3rd
 ctors are int vs void[]. With class D, the compiler suddenly gets all
 confused over whether Style is a typedef or not.
When I compile it, I get: ----------------------------------- test.d(8): constructor test.C.this called with argument types: (int,Style) matches both: test.C.this(int,Style) and: test.C.this(int,Style) ------------------------------------ This error is correctly diagnosed. You have two constructors with the same type signature. --------------------------------- test.d(8): cyclic constructor call --------------------------------- This error is also correctly diagnosed. -------------------------------------------------------- test.d(19): constructor test.D.this called with argument types: (ubyte[],Style) matches both: test.D.this(void[],Style) and: test.D.this(void[],uint,Style) -------------------------------------------------------------- This error is correctly diagnosed, as both matches are with implicit conversions. ---------------------------------------------------- test.d(28): constructor test.C.this called with argument types: (int) matches both: test.C.this(int,Style) and: test.C.this(int,uint,Style) ------------------------------------------------ This error is correctly diagnosed. It's ambiguous.
Dec 10 2005