Bug 9715 – Implement basic template error checking

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-14T02:18:34Z
Last change time
2023-03-27T13:51:43Z
Assigned to
No Owner
Creator
Don

Comments

Comment #0 by clugdbug — 2013-03-14T02:18:34Z
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.
Comment #1 by bugzilla — 2013-03-14T13:04:34Z
It's a good idea, but the pervasiveness of ErrorExp is still pretty incomplete.
Comment #2 by bugzilla — 2013-03-14T14:34:05Z
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.
Comment #3 by razvan.nitu1305 — 2023-03-27T13:51:43Z
Yes, this would require a major redesign of how the template system works for a rather small benefit.