Fantom

 

class

compiler::ConstChecks

sys::Obj
  compiler::CompilerSupport
    compiler::CompilerStep
      compiler::ConstChecks

ConstChecks adds hooks into constructors and it-blocks to ensure that an attempt to set a const field will throw ConstErr if not in the objects constructor. We also use this step to insert the runtime checks for non-nullable fields.

For each it-block which sets const fields:

doCall(Foo it)
{
  this.checkInCtor(it)
  ...
}

For each constructor which takes an it-block:

new make(..., |This| f)
{
  f?.enterCtor(this)
  ...
  checksField$Foo()  // if non-nullable fields need runtime checks
  f?.exitCtor()      // for every return
  return
}

Slots

curCtorSource

MethodDef? curCtor

fieldCheckSource

MethodDef? fieldCheck

makeSource

new make(Compiler compiler)

runSource

override Void run()

Run the step

visitStmtSource

override Stmt[]? visitStmt(Stmt stmt)

Callback when visiting a stmt. Return a list to replace the statement with new statements, or return null to keep existing statement.