Bug 11263 – Better code formatting in error messages with refused lambdas

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-14T15:05:17Z
Last change time
2021-05-15T14:12:03Z
Keywords
diagnostic
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-10-14T15:05:17Z
This is a low-priority spinoff of Issue 11258. Kenji Hara: > And I'd ask you one question: If the lambda has quite big body, how it will be > output? This is wrong example code: struct Foo { static int spam = 1; } struct Bar { static assert(__traits(compiles, { auto x = Foo.spam; })); } void main() {} dmd 2.064beta1 gives: test.d(5): Error: static assert (__traits(compiles, () { auto x = Foo.spam; } )) is false If the original code contains no newlines, then I think the compiler could avoid adding any newline and just copy the original code: test.d(5): Error: static assert(__traits(compiles, { auto x = Foo.spam; })) is false If at the time of the error printing the original formatting is lost, then the situation becomes more complex and you essentially need a little code beautifier like the GNU Indent program (http://www.gnu.org/software/indent/ ), but this is too much large and complex to implement. Having something like Indent in Phobos could be a good idea, but having it inside the compiler seems a bit too much. Perhaps during the generation of the error message the compiler could go back to read the original source code. If the solution is too much hard then please close down this issue.
Comment #1 by yebblies — 2013-11-16T20:55:55Z
There is _some_ room for improvement, but matching the original formatting is out of the question. You don't usually want the original text anyway, you want the result of semantic.
Comment #2 by snarwin+bugzilla — 2021-05-15T14:12:03Z
*** This issue has been marked as a duplicate of issue 10839 ***