Bug 2862 – ICE(template.c) using type tuple as function argument

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2009-04-20T08:51:00Z
Last change time
2014-02-15T13:13:14Z
Keywords
ice-on-invalid-code, patch
Assigned to
nobody
Creator
davidl

Comments

Comment #0 by davidl — 2009-04-20T08:51:08Z
import std.stdio; void bug(T...)(T t) { writefln(T); } void main() { bug(1,2); }
Comment #1 by clugdbug — 2009-10-21T03:11:17Z
An ancient bug. Reduced test case fails on D1 as well, as far back as 0.175. void foo(T...)(T t) {} void bug(T...)(T t){ foo(T); } void main(){ bug(1,2); }
Comment #2 by clugdbug — 2009-10-23T01:01:17Z
Root cause: should not be able to use a type as a function parameter. Currently, error messages are generated in the back-end, but some cases are missed. This moves the error message to the front-end where it belongs. --- Example of backend error now moved to front-end: void foo(int x){} alias int BAD; void main(){ foo(BAD); } --- And also note that non-type tuples are OK as function parameters. This test case still passes. int foo(T...)(T t) { return t[0]+t[1]; } template bug(T...){ int x = foo(T) + 4; } void main(){ int z = bug!(1, 2).x; assert(z==7); } --- Index: expression.c =================================================================== --- expression.c (revision 215) +++ expression.c (working copy) @@ -462,7 +462,10 @@ for (size_t i = 0; i < exps->dim; i++) { Expression *arg = (Expression *)exps->data[i]; - + if (arg->op == TOKtype) + { arg->error("type %s is not an expression", arg->toChars()); + arg = new IntegerExp(arg->loc, 0, Type::tint32); + } if (!arg->type) {
Comment #3 by clugdbug — 2009-10-23T23:15:46Z
Aargh, this doesn't work because types ARE valid function arguments inside type expressions. There does not seem to be better place to catch this error (functionArguments is too late). So a superficial patch is just to turn the ICE into an error message. It's not obvious how to phrase the error message so that it makes sense though. template.c line 4226. else { + if (ta->ty==Ttuple) { + ta->error(loc, "Type tuple %s is not a valid template argument", ta->toChars()); + continue; + } #ifdef DEBUG printf("ta = %d, %d, %s\n", ta->ty, Ttuple, ta->toChars()); #endif assert(global.errors); }
Comment #4 by leandro.lucarella — 2009-11-01T18:48:36Z
Comment #5 by bugzilla — 2009-11-06T11:30:02Z
Fixed dmd 1.051 and 2.036