The compiler swallows opDispatch errors

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Aug 30 12:48:33 UTC 2021


On Mon, Aug 30, 2021 at 12:19:21PM +0000, Adam D Ruppe via Digitalmars-d wrote:
> On Monday, 30 August 2021 at 06:13:03 UTC, bauss wrote:
> > I'd argue that opDispatch shouldn't have any constraints on it.
> 
> Well my rule would be if opDispatch is considered, the error shoudl be
> printed.
> 
> But you can prevent opDispatch from being considered by putting a
> constraint on it.
> 
> So
> 
> struct A {
>   void opDispatch(string s)() {
>         dfsdfsdf;
>   }
> }
> 
> A a;
> a.whatever; // REPORT THE FULL ERROR OMG
> 
> 
> BUT
> 
> 
> struct A {
>   void opDispatch(string s)() if(s != "whatever") {
>         dfsdfsdf;
>   }
> }
> 
> A a;
> a.whatever; // "no such property: whatver"
> 
> 
> so you only get "no such property" if the opDispatch is not considered
> at all because the outer constraint filtered it out.

But what about this then:

	struct A {
		void opDispatch(string s)() if (s0934hjslfadfAaarrgghh)
		{
			return;
		}
	}

Should this generate an error or not?


T

-- 
Why are you blatanly misspelling "blatant"? -- Branden Robinson


More information about the Digitalmars-d mailing list