groovy
  1. groovy
  2. GROOVY-4973

Inconsistent numeric range types

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.1
    • Fix Version/s: 1.8.5, 2.0-beta-2
    • Component/s: class generator
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      I would expect that range literal follow the same type promotion rules as arithmetic operations, yet:

      assert (1+10).class == Integer   
      assert (1L+10).class == Long 
      assert (1+10L).class == Long 
      
      assert (1..10).every { it.class == Integer  } 
      assert (1L..10).every { it.class == Long } 
      assert (1..10L).every { it.class == Integer } // <= weird 
      

        Activity

        Hide
        Roshan Dawrani added a comment -

        ObjectRange#constructorHelper(from, to) has the following piece commented out that should take care of this JIRA.

        Is there any concern in aligning from / to types like this?

                // TODO: Should we align to like types?
        //        if (from instanceof Integer && to instanceof Long) {
        //            from = Long.valueOf(((Integer) from).longValue());
        //        } else if (to instanceof Integer && from instanceof Long) {
        //            to = Long.valueOf(((Integer) to).longValue());
        //        }
        
        Show
        Roshan Dawrani added a comment - ObjectRange#constructorHelper(from, to) has the following piece commented out that should take care of this JIRA. Is there any concern in aligning from / to types like this? // TODO: Should we align to like types? // if (from instanceof Integer && to instanceof Long ) { // from = Long .valueOf((( Integer ) from).longValue()); // } else if (to instanceof Integer && from instanceof Long ) { // to = Long .valueOf((( Integer ) to).longValue()); // }
        Hide
        blackdrag blackdrag added a comment -

        looks like the comment was added as a reaction to GROOVY-2976, Paul 2008-09-06

        I think it is ok to do that change

        Show
        blackdrag blackdrag added a comment - looks like the comment was added as a reaction to GROOVY-2976 , Paul 2008-09-06 I think it is ok to do that change

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Dimitar Dimitrov
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: