www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9382] New: Alias declaration should not require the semantics completion of aliased template instance.

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

           Summary: Alias declaration should not require the semantics
                    completion of aliased template instance.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: k.hara.pg gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg gmail.com> 2013-01-23 21:23:05 PST ---
Essentially this code should succeed to compile, but in current it fails with
"recursive alias declaration" error.

code:
----
void main()
{
    CustomFloat!8 f;        // [1] line 3
}
template CustomFloat(uint bits)
{
    static if (bits ==  8) alias CustomFloat!( 4,  3) CustomFloat;  // [2] L7
    static if (bits == 64) alias CustomFloat!(52, 11) CustomFloat;
    static if (bits == 80) alias CustomFloat!(64, 15) CustomFloat;  // [6][8]
L9
}
struct CustomFloat(uint precision, uint exponentWidth)
{
    union ToBinary(F)
    {
        CustomFloat!(F.sizeof*8 < 80 ? F.sizeof*8 : 80) get;    // [5] L15
    }
    enum x = max_10_exp();  // run max_10_exp's semantic3

    static  property int max_10_exp()
    {
        CustomFloat max;
        return cast(int) max.get!real;    // [3][7] L22
    }
     property F get(F)()
    {
        ToBinary!F result;  // [4][8] L26
        return F.init;
    }
}

output:
----
test.d( 9): Error: alias test.CustomFloat!(80u).CustomFloat recursive alias
declaration
test.d(26): Error: template instance test.CustomFloat!(64,
15).CustomFloat.ToBinary!(real) error instantiating
test.d(22):        instantiated from here: get!(real)
test.d( 9):        instantiated from here: CustomFloat!(64, 15)
test.d(15):        instantiated from here: CustomFloat!(80u)
test.d(26):        instantiated from here: ToBinary!(real)
test.d(22):        instantiated from here: get!(real)
test.d( 7):        instantiated from here: CustomFloat!(4, 3)
test.d( 3):        instantiated from here: CustomFloat!(8)
----

The root cause of this issue is, if you make an alias of template instance, the
alias declaration will try to instantiate the template *completely*. If the
template is a template struct, its semantic() and semantic3() will run.
But in my thought, invoking semantic3 is not essentially be required for the
alias creation. Such the eager semantic will cause a unnecessary forward
reference, as above.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 23 2013
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9382



--- Comment #1 from github-bugzilla puremagic.com 2013-01-23 23:42:34 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/6502337a21a7ae3ce6519127a33c83b016a7408d
Add workaround for bug 9382, which introduced by fixing bug 5933

https://github.com/D-Programming-Language/phobos/commit/47d47579053c6c742d43e106d0d24a081fde3c35
Merge pull request #1096 from 9rnsr/fix5933

Add workaround for bug 9382, which introduced by fixing bug 5933

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 23 2013