[Issue 9715] New: Implement basic template error checking

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 14 02:18:37 PDT 2013


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 at puremagic.com
        ReportedBy: clugdbug at yahoo.com.au


--- Comment #0 from Don <clugdbug at 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: -------


More information about the Digitalmars-d-bugs mailing list