www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Unclear error message

reply SealabJaster <sealabjaster gmail.com> writes:
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?
Nov 10 2020
next sibling parent Paul Backus <snarwin gmail.com> writes:
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?
Nov 10 2020
prev sibling parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
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
Nov 10 2020
parent SealabJaster <sealabjaster gmail.com> writes:
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.
Nov 10 2020