[Issue 1536] New: Literal '0' is improperly used to deduce an implicit template parameter

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 28 11:09:45 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1536

           Summary: Literal '0' is improperly used to deduce an implicit
                    template parameter
           Product: D
           Version: 1.021
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: webmaster at villagersonline.com


EXAMPLE CODE
  void delegate() CurryAll(A...)(void delegate(A) dg, A args)
  {
    return null; // dummy function
  }
  struct S
  {
    void foo()
    {
      uint u = 0;
      int i = 0;

      // these work
      auto a = CurryAll       (&this.baz, 0);
      auto b = CurryAll!(uint)(&this.bar, 0);
      auto c = CurryAll       (&this.bar, u);
      auto d = CurryAll       (&this.baz, i);
      auto e = CurryAll!(uint)(&this.bar, i);
      auto f = CurryAll!( int)(&this.baz, u);

      // these don't
      auto z = CurryAll       (&this.bar, 0);
    }

    void bar(uint u) { return; }
    void baz( int i) { return; }
  }

DMD OUTPUT
  implicit_instantiation_and_implicit_cast.d(21): function
implicit_instantiation_and_implicit_cast.CurryAll!(int).CurryAll (void
delegate(int i),(int _param_1)) does not match parameter types (void
delegate((uint _param_1)),int)
  implicit_instantiation_and_implicit_cast.d(21): Error: cannot implicitly
convert expression (&(*this).bar) of type void delegate((uint _param_1)) to
void delegate(int i)

ANALYSIS

It appears that when DMD encounters the literal '0', it is jumping to the
conclusion that that literal '0' *must* be of type int, even though it could be
other types (uint, real, etc.).  In the case of the example z from above, this
is bad because the delegate argument quite clearly requires that the template
be deduced to have parameter uint.


-- 



More information about the Digitalmars-d-bugs mailing list