Thread overview
Typedef broken
Dec 08, 2005
Kris
Dec 10, 2005
Walter Bright
Dec 10, 2005
Kris
December 08, 2005
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.


December 10, 2005
"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.


December 10, 2005
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.
>
>