www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4960] New: dmd 2.049 rejects code containing templates with a uint as template parameter

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4960

           Summary: dmd 2.049 rejects code containing templates with a
                    uint as template parameter
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: CaptainSifff web.de



Created an attachment (id=778)
the failing piece of code

Hi there the following code is rejected by dmd 2.049
With the help of some helpful people in the D IRC channel I inserted the
pragmas into the code to highlight that dmd seems to somehow mix these two
identical types up.

If compiled the output is:
../../dmd2/linux/bin/dmd -O ChargeChargeCorrelation_Paste.d
C29ChargeChargeCorrelation_Paste18__T9MeanfieldVxk1Z1U
C29ChargeChargeCorrelation_Paste17__T9MeanfieldVk1Z1U
ChargeChargeCorrelation_Paste.d(23): Error: cannot implicitly convert
expression (timeevolver) of type
ChargeChargeCorrelation_Paste.main.Meanfield!(dimension).U to
ChargeChargeCorrelation_Paste.Meanfield!(dim).U

The first two lines coming from the pragmas.
If the alias is put into the global namespace the example compiles.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 30 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4960


Austin Hastings <ah08010-d yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ah08010-d yahoo.com



PDT ---
I get similar behavior on windows. Here is a smaller bit of code that
reproduces the issue (I think):
==========
    class U(uint dim) { }

    void chargecharge_entry(uint dim)( U!(dim) time )
    {
        //pragma(msg, "param: " ~ typeof( time ).mangleof);
    }

    void main() {

        const uint dimension = 1;
        alias U!(dimension) TimeEvolver;

        //pragma(msg, "main: " ~ TimeEvolver.mangleof);

        chargecharge_entry!(dimension)( new TimeEvolver );

    }

==========
For me emits:
test.d(41): Error: cannot implicitly convert expression (new U) of type
test.main.U!(dimension).U to test.U!(dim).U

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 30 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4960


bearophile_hugs eml.cc changed:

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



Also note the effect of this version of the same program:


template MeanField(int dim) {
    class U {
        cdouble opCall() {
            return 0.0 + 0.0i;
        }
    }
}

void chargeChargeEntry(int dim)(MeanField!(dim).U time) {
    pragma(msg, MeanField!(dim).U.mangleof);
}

void main() {
    alias MeanField!(1).U TimeEvolver;
    TimeEvolver timeEvolver = new TimeEvolver;
    pragma(msg, TimeEvolver.mangleof);
    chargeChargeEntry!(1)(timeEvolver);
}



Or even this version:


class U(int dim) {
    cdouble opCall() {
        return 0.0 + 0.0i;
    }
}

void chargeChargeEntry(int dim)(U!dim time) {
    pragma(msg, (U!dim).mangleof);
}

void main() {
    alias U!1 TimeEvolver;
    TimeEvolver timeEvolver = new TimeEvolver;
    pragma(msg, TimeEvolver.mangleof);
    chargeChargeEntry!(1)(timeEvolver);
}


See also bug 3467

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 30 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4960




I agree, your issue sounds similar,
but in contrast to your code where there might be a slight difference between
the 
types because the template takes an uint and you instantiate it with an int
literal, my example uses uints exclusively and the parameter dimension is typed
as an uint. So, there should be no reason for ambiguity...
I just tested your programs and they compiled with dmd 2.049...
Whereas changing austins example to using int doesn't lead to an compiling
program...
Essentially I don't get what's going wrong now...

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


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

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



13:05:57 PST ---
As a workaround you can use an enum instead of a const uint.

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