daniellansun commented on PR #3330:
URL: https://github.com/apache/groovy/pull/3330#issuecomment-7102396027

   Thanks Jochen. You are right: once we detect cycles deeper than a direct 
self-reference, `(this Collection)` is unclear. In your example the last marker 
in `[3, (this Collection)]` looks like `nestedList3` contains itself, but it 
actually points at `nestedList4`.
   
   I would like to keep `(this Collection)`, `(this Map)`, and `(this array)` 
only for a cycle back to the container that is currently being printed, which 
is the same case Java's `AbstractCollection.toString()` marks, and the same 
meaning these markers had before. When the cycle points at a container further 
up the render path, the marker should say so: `(ancestor Collection)`, 
`(ancestor Map)`, or `(ancestor array)`.
   
   Your example would then look like this:
   
   ```groovy
   assert nestedList4.toString() == '[[1, [(ancestor Collection)]], [2, 
[(ancestor Collection)]], [3]]'
   nestedList3 << nestedList4
   assert nestedList4.toString() == '[[1, [(ancestor Collection)]], [2, 
[(ancestor Collection)]], [3, (ancestor Collection)]]'
   ```
   
   A direct self-reference stays as it is today, for example `[1, (this 
Collection)]` for `list << list`. I have updated the tests, including this 
case, and pushed the change to this PR.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to