The following code fails to compile:
----------
uint[] data;
void benchmark(Algorithm alg) {
alg(data);
}
alias void function(uint[]) Algorithm;
----------
D:\My Documents\Programming\D\Tests\bugs\function_forward1.d(4): forward reference to type uint[]
----------
It took me a bit of work to figure what it was on about. How can a built-in type be forward referenced? I then realised that the forward reference was in fact to the Algorithm alias.
It turns out that the bug disappears if the parameter is uint rather than uint[].
Although the error line pinpoints the line where the function is called, the error still occurs if a use precedes the alias declaration but the call is placed after it. For example:
----------
uint[] data;
void benchmark(Algorithm alg) {
test(alg);
}
alias void function(uint[]) Algorithm;
void test(Algorithm alg) {
alg(data);
}
----------
D:\My Documents\Programming\D\Tests\bugs\function_forward2.d(10): forward reference to type uint[]
----------
Comment #1 by gide — 2009-05-25T07:29:07Z
Code crashes D2.
test.d
------
uint data;
void benchmark(Algorithm alg) {
alg(data);
}
alias void function(uint) Algorithm;
C:> dmd test.d
Assertion failure: 't->deco' on line 1125 in file 'mtype.c'
Comment #2 by clugdbug — 2009-05-25T13:53:13Z
(In reply to comment #1)
> Code crashes D2.
>
> test.d
> ------
> uint data;
>
> void benchmark(Algorithm alg) {
> alg(data);
> }
>
> alias void function(uint) Algorithm;
>
> C:> dmd test.d
> Assertion failure: 't->deco' on line 1125 in file 'mtype.c'
This ICE is fixed by my patch to bug 3010.
Comment #3 by clugdbug — 2009-07-07T08:22:37Z
The internal compiler error is fixed in DMD2.031. In fact it now works completely in D2. Still gives a forward reference error in D1.