Andreas Mayer created GROOVY-8443:
-------------------------------------

             Summary: GString should have a special case for Range instead of 
treating it as a Collection
                 Key: GROOVY-8443
                 URL: https://issues.apache.org/jira/browse/GROOVY-8443
             Project: Groovy
          Issue Type: Improvement
          Components: groovy-runtime
    Affects Versions: 2.4.13
            Reporter: Andreas Mayer


{{GString}} uses {{InvokerHelper}} to convert values to their textual 
representation. {{InvokerHelper}} in turn treats some types specially, for 
example, arrays and collections, but not ranges. As a result, ranges are 
formatted just like lists, because {{groovy.lang.Range}} implements 
{{java.lang.List}} and there is no special case for {{groovy.lang.Range}} 
itself.

The list-like representation is almost always longer and doesn't make it clear 
that the values in the list follow a rule. For huge ranges, it may even cause 
out-of-memory errors. 

{code}
def r1 = 1..10
assert r1.toString() == "1..10"
assert "$r1" == "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"

// Throws java.lang.OutOfMemoryError: Java heap space
def r2 = 1..1_000_000_0000
println "$r2"
{code}

Since ranges are first-class citizens, shouldn't {{InvokerHelper}} also 
implement a special case for {{groovy.lang.Range}}?



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to