January 09, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1775

           Summary: Code that compiles but shouldn't
           Product: D
           Version: 1.015
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: danijans03@student.kau.se


The code below compiles but it shouldn't. A more complex version of this problem caused dmd to segfault.

import std.stdio;

void main()
{
}

template ObjectException(T, U)
{
        class T : Exception
        {
                private U instance;

                public U data()
                {
                        return instance;
                }

                this(char[] msg)
                {
                        super(msg);
                }

                this(char[] msg, U object)
                {
                        super(msg);
                        instance =  object;
                }
        }

        unittest
        {
                class ImlException
                {
                }

                class test
                {
                }

                mixin ObjectException!(ImlException, test);
                test i = new test();
                ImlException ex = new ImlException("Ok",i);
                writefln(ex.msg);
        }
}


-- 

January 11, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1775


fvbommel@wxs.nl changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #1 from fvbommel@wxs.nl  2008-01-11 05:50 -------
Since the template is never instantiated[1] but is syntactically correct, the
code inside it is never semantically checked and completely compiled. Moving
the unittest outside of the template produces the following errors (when
compiled with -unittest):
===
test.d(44): Error: no constructor for ImlException
test.d(45): Error: no property 'msg' for type 'test.__unittest0.ImlException'
===

[1] outside of the template, at least; the nested unittest isn't instantiated until the template itself is instantiated and thus doesn't count since it won't go any further than syntax checking.


Anyway, closing this as invalid since there's no reason for the code not to compile. I suggest you submit a new bug report if you can get it to segfault again; otherwise ask for help in digitalmars.D.learn...


--