D issues are now
tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Summary: |
ICE(template.c) using type tuple as function argument |
Product: |
D
|
Reporter: |
david <davidl> |
Component: |
dmd | Assignee: |
No Owner <nobody> |
Status: |
RESOLVED
FIXED
|
Severity: |
normal
|
CC: |
bugzilla, clugdbug, leandro.lucarella
|
Priority: |
P2
|
Keywords: |
ice-on-invalid-code, patch |
Version: |
D1 (retired) |
Hardware: |
x86 |
OS: |
Windows |
import std.stdio;
void bug(T...)(T t)
{
writefln(T);
}
void main()
{
bug(1,2);
}
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);
}
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)
{
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 5
Walter Bright
2009年11月06日 11:30:02 UTC
Fixed dmd 1.051 and 2.036