digitalmars.D - "potentially malformed `opDispatch`"
- =?UTF-8?Q?Ali_=c3=87ehreli?= (24/24) Sep 27 2021 We talked about template instantiation problems hiding valuable
- Steven Schveighoffer (4/6) Sep 27 2021 I recently asked the same question, got mostly crickets:
- =?UTF-8?Q?Ali_=c3=87ehreli?= (3/11) Sep 27 2021 Oh! Ok, then... See you again next month... :)
- Nicholas Wilson (12/35) Sep 27 2021 I couldn't figure out how to recreate the failed expression to
We talked about template instantiation problems hiding valuable information before. Here is one: struct S { auto opDispatch(string symbol)() { static assert(symbol == "foo", "Invalid symbol."); } } void main() { S().bar; } Error: no property `bar` for type `deneme.S` potentially malformed `opDispatch`. Use an explicit instantiation to get a better error message opDispatch fails to compile because of my 'static assert' but my message "Invalid symbol." is lost. Granted, the compiler recommends me to do the following: S().opDispatch!"bar"; // Ok, now I get my error message 1) Can't we display my message in the first place? 2) If we can't, can the compiler itself instantiate explicitly to show the error message? 3) If not even that, can we really expect a newcomer to figure out what to do? At least we should apologize and provide the expression for the programmer to try again with. :) Ali
Sep 27 2021
On 9/27/21 3:33 PM, Ali Çehreli wrote:We talked about template instantiation problems hiding valuable information before. Here is one:I recently asked the same question, got mostly crickets: https://forum.dlang.org/post/sgb2m5$2eai$1 digitalmars.com -Steve
Sep 27 2021
On 9/27/21 12:45 PM, Steven Schveighoffer wrote:On 9/27/21 3:33 PM, Ali =C3=87ehreli wrote:Oh! Ok, then... See you again next month... :) AliWe talked about template instantiation problems hiding valuable=20 information before. Here is one:=20 I recently asked the same question, got mostly crickets:=20 https://forum.dlang.org/post/sgb2m5$2eai$1 digitalmars.com =20 -Steve
Sep 27 2021
On Monday, 27 September 2021 at 19:33:19 UTC, Ali Çehreli wrote:We talked about template instantiation problems hiding valuable information before. Here is one: struct S { auto opDispatch(string symbol)() { static assert(symbol == "foo", "Invalid symbol."); } } void main() { S().bar; } Error: no property `bar` for type `deneme.S` potentially malformed `opDispatch`. Use an explicit instantiation to get a better error message opDispatch fails to compile because of my 'static assert' but my message "Invalid symbol." is lost. Granted, the compiler recommends me to do the following: S().opDispatch!"bar"; // Ok, now I get my error message 1) Can't we display my message in the first place?I couldn't figure out how to recreate the failed expression to issue the underlying error. See [this pr](https://github.com/dlang/dmd/pull/12288)2) If we can't, can the compiler itself instantiate explicitly to show the error message?It might be possible, [this bit of code](https://github.com/dlang/dmd/blob/58653722e2be7abe61517505c06edf7680c933d1/src/dmd/ty esem.d#L3602-L3629) looks like it does something similar.3) If not even that, can we really expect a newcomer to figure out what to do? At least we should apologize and provide the expression for the programmer to try again with. :)That should be possible by formatting [this string](https://github.com/dlang/dmd/blob/d396a9e89c9e2a7ae687616231ba392c9ba7859d/src/ md/typesem.d#L2429) with: "...(rest of message)...`%s.opDispatch!\"%s\"`",mt.toPrettyChars(), ident.toChars() PRs welcome!
Sep 27 2021