flintlang / flint

The Flint Programming Language for Smart Contracts
MIT License
245 stars 18 forks source link

trait example in the document gives error #460

Open wmanshu opened 5 years ago

wmanshu commented 5 years ago
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.