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

trait example in the document gives error #460

Open
wmanshu opened this issue Aug 20, 2019 · 0 comments
Open

trait example in the document gives error #460

wmanshu opened this issue Aug 20, 2019 · 0 comments

Comments

@wmanshu
Copy link

wmanshu commented Aug 20, 2019

contract trait Ownable {
  event OwnershipRenounced(previousOwner: Address)
  event OwnershipTransfered(previousOwner: Address, newOwner: Address)

  self :: (any) {
    public func getOwner() -> Address
  }

  self :: (getOwner) {
    func setOwner(newOwner: Address)

    public func renounceOwnership() {
      emit OwnershipRenounced(getOwner())
      setOwner(0x0000000000000000)
    }

    public func transferOwnership(newOwner: Address) {
      assert(newOwner != 0x0000000000000000)
      emit OwnershipTransfered(getOwner(), newOwner)
      setOwner(newOwner)
    }
  }
}

contract ToyWallet: Ownable {
  visible var owner: Address // visible automatically creates getOwner
  // Skipping initialiser not relevant for this example
}

ToyWallet :: (any) {
  public init(addr: Address) {
    self.owner = addr
  }
  public func getOwner() -> Address {
    return owner
  }
}

ToyWallet :: (getOwner) {
  func setOwner(newOwner: Address){
    self.owner = newOwner
  }
}

Error happens at line self :: (getOwner), the error message is Unexpectedly found nil. It is also not possible to change it to getOwner(), which gives another error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants