D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11263 - Better code formatting in error messages with refused lambdas
Summary: Better code formatting in error messages with refused lambdas
Status: RESOLVED DUPLICATE of issue 10839
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2013-10-14 15:05 UTC by bearophile_hugs
Modified: 2021-05-15 14:12 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2013-10-14 15:05:17 UTC
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 yebblies 2013-11-16 20:55:55 UTC
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 Paul Backus 2021-05-15 14:12:03 UTC

*** This issue has been marked as a duplicate of issue 10839 ***