Ali Çehreli:
That would be great but there are many other cases where the
compiler does not do anything like that. Here, it would have to
decide similar to "even though this is a runtime foreach, I
know at compile time that 'result' is a fixed-length array so
'i' is between 0 and 10. I also have this compile-time tuple
template parameters. Now let me see whether running that code
would produce values that would fit the 'result's type ubyte."
I don't think we are there yet. :)
Adding a bit more static analysis to D will help making D a bit
more modern language. Having something like "liquid types" is
very good, but I think that even much more limited capabilities
are enough to avoid avoid some casts and bugs.
Recently I have added a related (simple) enhancement request,
perhaps it's implementable:
http://d.puremagic.com/issues/show_bug.cgi?id=10594
Bye,
bearophile