Fix issue 20261 - lambda function error message is confusing - #23835
usefahmed07 wants to merge 1 commit into
Conversation
When a function literal's parameter types are inferred (e.g. 'x => c' with no explicit types), it gets compiled as a template internally. The error for accessing an outer variable then exposed the compiler- generated identifier (e.g. __lambda3(__T1)) via toPrettyChars(), and mislabeled it as a plain 'function' when it was actually a template declaration at that point. Now, when the inaccessible-frame error is reported for such a templated function literal, the message says 'lambda function' instead of surfacing the internal name. Fixes https://issues.dlang.org/show_bug.cgi?id=23847
|
I don't think this is an improvement, let alone totally inconsistent if only done here, or selectively for a few other messages. |
Thanks for the feedback. Just to understand better — do you think the original |
|
My main problem is the inconsistency - either we print all lambdas in a generic fashion without the internal identifier, with its line+column suffix, everywhere (for all diagnostics, and implemented only once), or we keep things as is - which I'd prefer, since the line number can be handy at times (it's the line where the lambda starts). The original #20261 is about the internal counter suffix that we used back then, instead of that line+column suffix nowadays. So I think it's invalid nowadays, even though it's certainly confusing that for that specific error message, the template declaration seems to be printed, not the template instance, where the |
|
Looking again at the original code in the issue, I doubt that printing the template instance is easily feasible here - inferring the type for untyped parameter But feel free to try to improve that. :) |
Tried it — it actually works. Added a debug printf and confirmed the TemplateInstance's tiargs are already resolved by the time the error fires. For example, with: Current output shows the unbound template declaration: Switching Location is kept, and the placeholder types (__T1, __T2) become the actual resolved ones (int, int). I'll push this to this PR instead of the generic "lambda function" approach, unless you'd prefer something different. |
Fixes #20261