The compiler swallows opDispatch errors

Steven Schveighoffer schveiguy at gmail.com
Mon Aug 30 13:02:52 UTC 2021


On 8/30/21 8:48 AM, H. S. Teoh wrote:
> 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?

Let's see:

```d
void foo()() if (s0934hjslfadfAaarrgghh) {}


void main()
{
    foo();
}
```

```
onlineapp.d(1): Error: undefined identifier `s0934hjslfadfAaarrgghh`
onlineapp.d(7): Error: `foo()() if (s0934hjslfadfAaarrgghh)` has no effect
```

Yes, it should, if considered.

-Steve


More information about the Digitalmars-d mailing list