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

           Summary: opDispatch produces confusing error message when
                    rejected by a template constraint
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: turkey...@gmail.com


--- Comment #0 from Manu <turkey...@gmail.com> 2012-05-15 07:14:57 PDT ---
I have a case like this:

template isValid(string s)
{
  // screen for valid opDispatch patterns
  enum bool isValid = s == "foo";
}

struct T
{
  int opDispatch(string s) if(isValid!s)
  {
    // do something 
    return 0;
  }

  int a;
}

T t;

auto i = t.a;   <-- this is fine
auto j = t.foo; <-- this is captured by opDispatch, this is fine.
auto k = t.bar; <-- opDispatch is not invoked with "bar", so this fails, but
produces a horrible error message

If opDispatch is not present, an attempt to access bar produces the error:
 Error: No property 'bar' for type T

If opDispatch is present, even though the constraint prevents it from being
invoked with the given argument, it produces a very confusing template error:
 Error: template instance opDispatch!("bar") opDispatch!("bar") does not match
template declaration opDispatch(string s) if (isValid!s)

This has confused everyone in the building so far (new to D). People are not
expecting a template error when they make a typo, or address something that
isn't a member of the class.

It would be nice if when opDispatch has constraints on it, preventing the
template from being invoked under some conditions, that it would revert to the
original expected error message.

If the compiler would say "okay, bar didn't match and neither did opDispatch
invoke with it, give a normal error, not a template instantiation error", this
would save some confusion :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to