Thread overview
Unclear error message
Nov 11, 2020
SealabJaster
Nov 11, 2020
Paul Backus
Nov 11, 2020
H. S. Teoh
Nov 11, 2020
SealabJaster
November 11, 2020
Please see the code at https://run.dlang.io/is/Yjidek

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

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?
November 11, 2020
On Wednesday, 11 November 2020 at 01:05:21 UTC, SealabJaster wrote:
> Please see the code at https://run.dlang.io/is/Yjidek
>
> As I understand the error is caused by trying to provide a delegate when there's no context to provide. Not complaining about that.
>
> 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?

Yeah, that message is really bad. The actual problem is that the compiler isn't able to figure out the type of the lambda you've provided. If you change the argument to `(string str)`, it'll work.

The real question is, why does type inference fail for the UDA when it works for the normal constructor call?
November 10, 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
November 11, 2020
On Wednesday, 11 November 2020 at 02:05:33 UTC, H. S. Teoh wrote:
> Definitely. Bad/confusing error messages should always be improved. Please file a bug at:
>
> 	http://issues.dlang.org/
>
>
> T

https://issues.dlang.org/show_bug.cgi?id=21377

I wonder if this is the same as: https://issues.dlang.org/show_bug.cgi?id=21003

I filed it either way, just in case.