www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8097] New: opDispatch produces confusing error message when rejected by a template constraint

reply d-bugmail puremagic.com writes:
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: nobody puremagic.com
        ReportedBy: turkeyman gmail.com



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: -------
May 15 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8097




This seems to be fixed, but a new issue has taken it's place; if there is an
error in the opDispatch, or even in it's constraint, it will silently fail and
produce the error "No property: blah", as if there were no opDispatch at all.

Ie, it no longer gives compile errors within opDispatch, and compile errors are
useful :)

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