www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22000] New: Identical candidates shown when templates differ

https://issues.dlang.org/show_bug.cgi?id=22000

          Issue ID: 22000
           Summary: Identical candidates shown when templates differ by
                    template constraints
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: mipri minimaltype.com

This code

  int four(T)() if (is(T == int)) { return 4; }
  string four(T)() if (is(T == string)) { return "four"; }

  unittest {
      int f = four();
      assert(four!int == 4);
      assert(four!string == "four");
  }

fails with this template error which offers two identical candidates:

  tmpl.d(5): Error: template `tmpl.four` cannot deduce function from argument
types `!()()`, candidates are:
  tmpl.d(1):        `four(T)()`
  tmpl.d(2):        `four(T)()`

If the two asserts are moved above the failing line, a more useful error is
produced:

  tmpl.d(7): Error: template `tmpl.four` cannot deduce function from argument
types `!()()`, candidates are:
  tmpl.d(1):        `four(T)()`
    with `T = string`
    must satisfy the following constraint:
  `       is(T == int)`
  tmpl.d(2):        `four(T)()`

At a guess, this is related to the resolution of Issue 7768

Seen with DMD64 D Compiler v2.097.0

--
Jun 06