Unclear error message

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Nov 11 02:05:33 UTC 2020


On Wed, Nov 11, 2020 at 01:05:21AM +0000, SealabJaster via Digitalmars-d-learn wrote:
> Please see the code at https://run.dlang.io/is/Yjidek

[Quoting code in full here for future reference]

> struct PreValidate
> {
>     alias FuncT = bool delegate(string arg);
> 
>     FuncT func;
> 
>     this(FuncT func)
>     {
>         this.func = func;
>     }
> 
>     bool onPreValidate(string arg)
>     {
>         return this.func(arg);
>     }
> }
> 
> // OK
> @PreValidate(str => str.length == 3)
> int i;
> 
> void main()
> {
>     // OK
>     auto v = PreValidate(str => str.length == 3);
> }
> 
> struct S
> {
>     // ERROR?
>     @PreValidate(str => str.length == 3)
>     int a;
> }


> As I understand the error is caused by trying to provide a delegate
> when there's no context to provide. Not complaining about that.

Is this even a valid error? The UDA works in module scope, where there
*isn't* any local context, yet it's accepted, but here, in a struct,
it's not accepted.  I'm not 100% but this looks like a bug.


> However what I am complaining about is about the error message:
> `onlineapp.d(31): Error: delegate onlineapp.S.__lambda2 cannot be
> struct members`
> 
> I'm not sure if it's just me, but that error message makes absolutely
> no sense to me. Should that message be improved?

Definitely. Bad/confusing error messages should always be improved.
Please file a bug at:

	http://issues.dlang.org/


T

-- 
Unix was not designed to stop people from doing stupid things, because that would also stop them from doing clever things. -- Doug Gwyn


More information about the Digitalmars-d-learn mailing list