You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
resources/tests/type_checker_tests/InStateOwnership.obs 63.13: Variable 'a' holds ownership, but is unused at the end of its scope.
asset contract Money {
int value;
Money @ Owned(int v) { // Constructor returns a reference that is owned by the callee.
value = v;
}
transaction getValue() returns int {
return value;
}
// merge can be called via an Unowned reference to the receiver (this).
transaction merge(Money @ Unowned this, Money @ Owned >> Unowned m) {
value = value + getValue();
disown m; // We have combined the value of m with our own value, so throw away m.
}
// split can only be called via an Owned reference to the receiver (this).
transaction split(Money @ Owned this, int amt) returns Money @ Owned {
if (amt <= value) {
value = value - amt;
return new Money(amt);
} else {
revert ("Not enough money in account."); // Abort the transaction.
}
}
}
asset contract Account {
state Open {
Money @ Owned money;
}
state Closed;
Account@Closed() {
->Closed;
}
transaction open(Account @ Closed >> Open this) {
->Open(money = new Money(0));
}
transaction close(Account @ Open >> Closed this) returns Money @ Owned {
Money balance = money;
->Closed;
return balance;
}
transaction deposit(Account @ Open this, Money @ Owned >> Unowned m) {
money.merge(m); // OK, merges m into money.
}
transaction withdraw(Account @ Open this, int amount) returns Money @ Owned {
return money.split(amount);
}
}
main contract C {
transaction t (Account @ Shared a) returns Money @ Owned {
if (a in Open) {
return a.withdraw(10); // Should not give an error, but does.
}
return new Money(0);
}
}
The text was updated successfully, but these errors were encountered:
resources/tests/type_checker_tests/InStateOwnership.obs 63.13: Variable 'a' holds ownership, but is unused at the end of its scope.
The text was updated successfully, but these errors were encountered: