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

--- Comment #0 from Manu <> 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 =; <-- this is captured by opDispatch, this is fine.
auto k =; <-- 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:
------- You are receiving this mail because: -------

Reply via email to