#1196 Compilation error with "++"

yachris Sat 4 Sep 2010

Hello,

The following won't compile:

class MockRandom : Random
{
  new make(Int[] values) : super()
  {
    valuesToReturn = values
    index = 0
  }

  override Int random(Range range)
  {
    result := valuesToReturn[index]
    ++index
    if (index > valuesToReturn.size)
    {
      index = 0
    }
    return result
  }

  private Int[] valuesToReturn
  private Int index
}

However, if I replace the "++index" with "index++" it compiles. The documentation seems to indicate that either is usable... and I prefer the prefix form. Guess I know which form Brian and Andy like :-)

andy Sat 4 Sep 2010

Looks like that might just be an issue of needing a trailing ;- so these two lines aren't treated as a single expression:

result := valuesToReturn[index];  // need semicolon
++index

brian Mon 6 Sep 2010

We decided and already have a ticket to require a newline so that the semicolon isn't required - see #1150.

Login or Signup to reply.