groovy

Assignment to array element yields null

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0, 1.1-beta-1
  • Fix Version/s: 1.1-beta-2
  • Component/s: bytecode
  • Labels:
    None
  • Environment:
    Windows XP
    Java SE 6
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

Assigning a value to an array element yields null instead of the assigned value.

int[] a = new int[1]
assert (a[0] = 42) == null // current behavior
assert (a[0] = 42) == 42 // expected behavior

Activity

Hide
Peter Niederwieser added a comment -

I suggest to keep putAt() a "void" method and just make a[0]=42 evaluate to 42 rather than null. This is consistent with properties, where setters have return type void and therefore a.setX(42) evaluates to null, whereas a.x=42 evaluates to 42.

Show
Peter Niederwieser added a comment - I suggest to keep putAt() a "void" method and just make a[0]=42 evaluate to 42 rather than null. This is consistent with properties, where setters have return type void and therefore a.setX(42) evaluates to null, whereas a.x=42 evaluates to 42.
Hide
blackdrag blackdrag added a comment -

implemented

Show
blackdrag blackdrag added a comment - implemented

People

Vote (1)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: