old variable generation on inherited instance variables
Reported by me (at andresteingress) | April 11th, 2011 @ 08:57 PM | in 1.2.4
it seems that the old variable generation does not work on inherited instance variables:
import org.gcontracts.annotations.*
// by http://www.javacoffeebreak.com
class Account
{
protected BigDecimal balance
def Account( BigDecimal amount = 0.0 )
{
balance = amount
}
void deposit( BigDecimal amount )
{
balance += amount
}
@Requires({ amount >= 0.0 })
// @Ensures({ balance == old.balance - amount })
BigDecimal withdraw( BigDecimal amount )
{
if (balance < amount) return 0.0
balance -= amount
return amount
}
BigDecimal getBalance()
{
return balance
}
}
class BetterAccount extends Account {
@Ensures({ balance == old.balance - (amount * 0.5) })
BigDecimal withdraw( BigDecimal amount )
{
if (balance < amount) return 0.0
balance -= amount * 0.5
return amount
}
}
Account account = new BetterAccount()
account.deposit(30)
account.withdraw(10) // could be a program bug
account.balance // uniform access principle: uniform access to computed or in-memory vals
Comments and changes to this ticket
-
me (at andresteingress) April 11th, 2011 @ 09:07 PM
the problem occurs only if the inherited class computes the old variables map, but the predecessor does not.
-
me (at andresteingress) May 12th, 2011 @ 08:09 PM
- Milestone changed from 1.2.2 to 1.2.3
- Milestone order changed from 10 to 0
-
me (at andresteingress) May 18th, 2011 @ 11:17 AM
- Milestone changed from 1.2.3 to 1.2.4
- Milestone order changed from 4 to 0
-
me (at andresteingress) May 23rd, 2011 @ 09:17 PM
- Milestone order changed from 1 to 0
(from [ae3ced841930f2e1a20bfc9b62bc97292d02ea3e]) fixed [#17] old variable generation on inherited instance variables https://github.com/andresteingress/gcontracts/commit/ae3ced841930f2...
-
me (at andresteingress) May 23rd, 2011 @ 09:17 PM
- State changed from new to resolved
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
core module
People watching this ticket
Referenced by
- 17 old variable generation on inherited instance variables (from [ae3ced841930f2e1a20bfc9b62bc97292d02ea3e]) fixed [...