Value Range Propagation with generic and specialized function

Wagner Macedo via Digitalmars-d digitalmars-d at puremagic.com
Thu May 22 16:37:43 PDT 2014


Hello,

Firstly, I'm not an actual D programmer. I'm doing a college
research about D language.

My point here is that I faced the following situation.

With the code above

      void main() {
          fun(1f);
          fun(1);
          fun(1L);
          fun!(long)(1L);
      }

      void fun(T)(T i) {
          writeln(typeid(T));
      }

      void fun(int i) {
          writeln("special => int");
      }

I get the output

      float
      special => int
      special => int
      long

that is, even if I call fun(1L), with long literal, the VRP
decide to use specialized fun(int). Due this, it's needed to
specify that I need to use the generic function (losing
readability).

Said this, I wanted to know if this is a bug or an expected
behavior.


More information about the Digitalmars-d mailing list