www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9715] New: Implement basic template error checking

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

           Summary: Implement basic template error checking
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: clugdbug yahoo.com.au


--- Comment #0 from Don <clugdbug yahoo.com.au> 2013-03-14 02:18:34 PDT ---
int foo(T)(T x, int yesterday)
{
    return yesteray;
}
----
There is a typo in this template, it will fail for any type T. Would be nice if
this reported an error, without having to instantiate the template.

We could do this by creating a new Unspecified type and UnspecifiedExp in the
compiler. Whenever a template declaration is encountered, instantiate it with
Unspecified types. These guys would propagate exactly like ErrorExp.

Then, we'd get error messages for the simple cases like those shown above.

You could actually do 'static if' the same way (types declared in is()
expressions inside static if will be Unspecified type if they depend on
template parameters), but the challenge is when you have multiple independent
static ifs in a template:

static if (T.sizeof == 2)  int x = 3;
static if (T.sizeof > 2)  int x = 4;  // this isn't a redefinition error

There are ways to deal with this, eg treating the inside of the static if as a
scope, and when the static if has been analyzed, moving everything declared in
that scope into the parent scope, marking it as PossiblyDeclared.
(so that redefining it doesn't cause an error, but it's OK to use it from
inside another static if).

The simpler option would be to stop analysis after the first 'static if' is
encountered. That would still catch errors in a lot of useful cases.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 14 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9715


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #1 from Walter Bright <bugzilla digitalmars.com> 2013-03-14
13:04:34 PDT ---
It's a good idea, but the pervasiveness of ErrorExp is still pretty incomplete.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 14 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9715



--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2013-03-14
14:34:05 PDT ---
Another issue is what happens with value and alias parameters. A fair amount of
reengineering of the internals would be necessary to make this work.

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