Bug 22043 – assert_writeln_magic produces confusing examples

Status
NEW
Severity
normal
Priority
P3
Component
tools
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-06-19T12:16:53Z
Last change time
2024-08-01T16:03:53Z
Assigned to
No Owner
Creator
Tomoya Tanjo

Comments

Comment #0 by ttanjo — 2021-06-19T12:16:53Z
I tentatively set the component field of this bug to `dlang.org` but I'm not sure it is an appropriate. Please fix the component field if another component is more appropriate for it. The example of `outdent` is wrong in dlang.org because there is a missing indent for the line `writeln("Hello");` in `ugly` as follows. - https://dlang.org/phobos-prerelease/std_string.html#.outdent ```dlang enum pretty = q{ import std.stdio; void main() { writeln("Hello"); } }.outdent(); enum ugly = q{ import std.stdio; void main() { writeln("Hello"); } }; writeln(pretty); // ugly ``` However, the original documented unittest in std.string.outdent is correct as follows: - https://github.com/dlang/phobos/blob/afb382485b3625e149bb20d593b6d1fe679410af/std/string.d#L6903 ```dlang @safe pure unittest { enum pretty = q{ import std.stdio; void main() { writeln("Hello"); } }.outdent(); enum ugly = q{ import std.stdio; void main() { writeln("Hello"); } }; assert(pretty == ugly); } ``` It seems a bug in the document generator in dmd or related components.
Comment #1 by moonlightsentinel — 2021-06-20T12:06:50Z
Changed the component to tools because the asserts are replaced by `assert_writeln_magic.d`.
Comment #2 by nick — 2024-08-01T16:00:49Z
> writeln(pretty); // ugly lineSplitter is even worse: https://dlang.org/phobos/std_string.html#lineSplitter > writeln(lineSplitter(s).array); // splitLines(s) What? Does it mean the two expressions are equivalent??! Then: foreach (line; lines) { writeln(line); // witness[i++] } writeln(i); // witness.length Transforming those assert statements makes them unintelligible. It should only do it (if at all) when the right hand side has no side effects and is not a function call. It's OK when the RHS is a literal.