get method

dynamic get(
  1. String name
)

Retrieves the value associated with name, throwing RuntimeD4rtException("Undefined variable: ...") when it is absent.

Thin wrapper over lookup: this is the throwing contract the bulk of the interpreter relies on. Resolution callers that fall back on a miss (e.g. implicit-this member access in InterpreterVisitor.visitSimpleIdentifier) should call lookup directly to avoid the cost of constructing, throwing and catching an exception — with its stack-trace capture — on every miss.

The message is built by undefinedVariableMessage, which appends a reason when name is one of the deliberately-unbridged SDK identifiers (SCB30).

A variable initialized lazily - a static or top-level one with an initializer, or a late one - reads as its VALUE, initializing it if needed (GitHub #10), as any read of it in a script does. Code that must see the LateVariable holder itself, to assign through it, uses getBinding.

Implementation

dynamic get(String name) {
  final value = getBinding(name);
  return value is LateVariable ? value.value : value;
}