flintrocks / flint

The Flint Programming Language for Smart Contracts
MIT License
2 stars 0 forks source link

Check that all member are initialised after construction #101

Open Aurel300 opened 5 years ago

Aurel300 commented 5 years ago

(Result of #30)

Currently, this is valid code:

struct X {
  var a: Int

  public init() {
    if (false) {
      a = 2
    }
  }
}

This is because the check for the initialisation of all variables is insufficient. It does not check variable initialisation in nested function calls, does not do CFA, etc. A proper solution is out of scope for this project.

For now the suggested workaround is to separate the initialisers into two parts – variable declarations and the rest of the code.

public init() {
  // variable initialisation
  self.x = 3

  // rest of the code
  self.someFuncUsing(x: self.x)
}

Before the first function call, or the end of the initialiser (whichever comes first), all variables should be initialised.