Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erroneous error message due to return inside if-in-state test #280

Open
mcoblenz opened this issue Nov 20, 2019 · 0 comments
Open

Erroneous error message due to return inside if-in-state test #280

mcoblenz opened this issue Nov 20, 2019 · 0 comments
Labels

Comments

@mcoblenz
Copy link
Owner

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);
    }
}
@mcoblenz mcoblenz added the bug label Nov 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant