groovy
  1. groovy
  2. GROOVY-2556

Assignment Operator returns not always the right values

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.5.2
    • Fix Version/s: 1.5.3
    • Component/s: None
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      The test case at the bottom runs with 1.5.0 and 1.5.1 and fails with 1.5.2.

      The failing test with 1.5.2 is testAssignmentWithMap

      class AssignmentTest extends GroovyTestCase {
          final String SOME_METHOD_VALUE = 'someMethodValue'
          final String TEST_NAME = 'someName'
      
          String s
      
          Map names
      
          void setUp() {
              names = [:]
          }
          
          void testAssignmentWithString() {
              assertEquals(SOME_METHOD_VALUE, someMethod())
          }
      
          void testAssignmentWithMap() {
              assertEquals(TEST_NAME, addName(TEST_NAME))
          }
      
          String someMethod() {
              s = SOME_METHOD_VALUE
          }
      
          String addName(String name) {
              names[name] = name
          }
      }
      

        Activity

        Hide
        Jim White added a comment -

        Failures also occur with arrays and may vary depending on context (whether in closure or not):

        class AssignmentTest extends GroovyTestCase {
        final String SOME_METHOD_VALUE = 'someMethodValue'
        final String TEST_NAME = 'someName'

        String s

        Map names

        void setUp()

        { names = [:] }

        void testAssignmentWithString()

        { assertEquals(SOME_METHOD_VALUE, someMethod()) }

        // This fails in 1.5.2
        void testAssignmentWithMap()

        { assertEquals(TEST_NAME, addName(TEST_NAME)) }

        String someMethod()

        { s = SOME_METHOD_VALUE }

        String addName(String name)

        { names[name] = name }

        // This fails in 1.0, 1.5.0, 1.5.1, 1.5.2
        void testArrayAssignment()

        { def arr = [*0..4] assert 33 == (arr[2] = 33) }

        // This fails in 1.5.2
        void testArrayAssignmentInClosure() {
        def arr = [*0..4]
        assert 55 ==

        { arr[2] = 55 }

        .call()
        }

        void testVarAssignment()

        { def var = 1 assert 77 == ( var = 77) }

        void testVarAssignmentInClosure() {
        def var = 1
        assert 22 ==

        { var = 22 }

        .call()
        }
        }

        Show
        Jim White added a comment - Failures also occur with arrays and may vary depending on context (whether in closure or not): class AssignmentTest extends GroovyTestCase { final String SOME_METHOD_VALUE = 'someMethodValue' final String TEST_NAME = 'someName' String s Map names void setUp() { names = [:] } void testAssignmentWithString() { assertEquals(SOME_METHOD_VALUE, someMethod()) } // This fails in 1.5.2 void testAssignmentWithMap() { assertEquals(TEST_NAME, addName(TEST_NAME)) } String someMethod() { s = SOME_METHOD_VALUE } String addName(String name) { names[name] = name } // This fails in 1.0, 1.5.0, 1.5.1, 1.5.2 void testArrayAssignment() { def arr = [*0..4] assert 33 == (arr[2] = 33) } // This fails in 1.5.2 void testArrayAssignmentInClosure() { def arr = [*0..4] assert 55 == { arr[2] = 55 } .call() } void testVarAssignment() { def var = 1 assert 77 == ( var = 77) } void testVarAssignmentInClosure() { def var = 1 assert 22 == { var = 22 } .call() } }
        Hide
        Jim White added a comment -

        Again with effects...

        Failures also occur with arrays and may vary depending on context (whether in closure or not):

        class AssignmentTest extends GroovyTestCase {
            final String SOME_METHOD_VALUE = 'someMethodValue'
            final String TEST_NAME = 'someName'
        
            String s
        
            Map names
        
            void setUp() {
                names = [:]
            }
            
            void testAssignmentWithString() {
                assertEquals(SOME_METHOD_VALUE, someMethod())
            }
        
            // This fails in 1.5.2
            void testAssignmentWithMap() {
                assertEquals(TEST_NAME, addName(TEST_NAME))
            }
        
            String someMethod() {
                s = SOME_METHOD_VALUE
            }
        
            String addName(String name) {
                names[name] = name
            }
            
            // This fails in 1.0, 1.5.0, 1.5.1, 1.5.2
            void testArrayAssignment() {
                def arr = [*0..4]
                assert 33 == (arr[2] = 33)
            }
        
            // This fails in 1.5.2
            void testArrayAssignmentInClosure() {
                def arr = [*0..4]
                assert 55 == { arr[2] = 55 }.call()
            }
        
            void testVarAssignment() {
                def var = 1
                assert 77 == ( var = 77)
            }
        
            void testVarAssignmentInClosure() {
                def var = 1
                assert 22 == { var = 22 }.call()
            }
        }
        
        Show
        Jim White added a comment - Again with effects... Failures also occur with arrays and may vary depending on context (whether in closure or not): class AssignmentTest extends GroovyTestCase { final String SOME_METHOD_VALUE = 'someMethodValue' final String TEST_NAME = 'someName' String s Map names void setUp() { names = [:] } void testAssignmentWithString() { assertEquals(SOME_METHOD_VALUE, someMethod()) } // This fails in 1.5.2 void testAssignmentWithMap() { assertEquals(TEST_NAME, addName(TEST_NAME)) } String someMethod() { s = SOME_METHOD_VALUE } String addName(String name) { names[name] = name } // This fails in 1.0, 1.5.0, 1.5.1, 1.5.2 void testArrayAssignment() { def arr = [*0..4] assert 33 == (arr[2] = 33) } // This fails in 1.5.2 void testArrayAssignmentInClosure() { def arr = [*0..4] assert 55 == { arr[2] = 55 }.call() } void testVarAssignment() { def var = 1 assert 77 == ( var = 77) } void testVarAssignmentInClosure() { def var = 1 assert 22 == { var = 22 }.call() } }
        Hide
        Paul King added a comment -

        close off release 1.5.4

        Show
        Paul King added a comment - close off release 1.5.4

          People

          • Assignee:
            Alex Tkachman
            Reporter:
            Hans Dockter
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: