const s = foo(); // compiles if type of s is specified explicitly char[] foo() // seems to fail only if the return type is char[] { return null; }
Compiles if the declaration of s goes after foo definition
This does work with dmd 2.013.
Right, but the bug is in the 1.x branch, which is still in use :)
The test case is a bit misleading. It requires an alias to the type which is being inferred. With the original test case, it was provided by alias char[] string; in std.object. Here's a complete test case. Remove the alias, and it will be fine. --- alias int * any_old_alias; const bar = foo; int * foo = null; --- The alias creates a corrupt type (it doesn't have the 'deco' member set), and this gets picked by 'bar' instead of the type of foo. The behaviour is quite similar to 2672. Marking as critical, because subtle changes in ordering in different modules can control whether the segfault occurs.
Aargh, I'm wrong, it just has to be any forward reference. This really simple test case segfaults in a completely different place (cast.c), with a much more obviously corrupt type. const bar = foo; const int * foo = null;
I've moved the new test case to bug#3493 (segfault, cast.c). The original bug now generates a forward reference error; the reduced test case (below) is now an ICE instead of a segfault. This should be considered as the test-case for this bug. ---- alias int * any_old_alias; const bar = foo; int * foo = null; ----
This applies to D2 as well. The D2 test case (below) generates: "Error: forward reference to type int*" on D1. On D2 it ICEs in mangle.c(81) fd && fd->inferRetType Removing the alias fixes both the ICE and the forward reference error. Happens with typedef as well as alias. ----- alias int * any_old_alias; typeof(foo) bar = foo; const int * foo = null;
Fixed svn 755.