On Tuesday, September 11, 2012 23:55:40 bearophile wrote: > Namespace: > > But so far no suggestions? > > This seems to work, but solutions that use cast() are sometimes > fragile (and dangerous): > > > auto foo(bool b) { > final switch (b) { > case false: > return 20.0; > case true: > return cast(typeof(return))10; > } > } > void main() { > import std.stdio: writeln; > writeln(foo(false)); > writeln(foo(true)); > }
If you're going to use a cast, then use one where you give the type explicitly. Using typeof(return) is just asking for it when the compiler is clearly already having issues with the return type. - Jonathan M Davis