Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

dmd.dfa.fast.report

Reporting mechanism for the fast Data Flow Analysis engine.
This module translates the abstract state of the DFA into concrete compiler errors. It is responsible for:
  1. Null Checks: Reporting errors when null pointers are dereferenced.
  2. Contract Validation: Ensuring functions fulfill their out contracts (e.g., returning non-null).
  3. Logic Errors: Detecting assertions that are provably false at compile time.
struct DFAReporter;
The interface for reporting DFA errors and warnings.
This struct acts as the sink for all findings. It checks if a specific violation (like a null dereference) should be reported based on the variable's modellability and depth, then sends it to the global ErrorSink.
void onDereference(DFAConsequence* on, ref Loc loc);
Reports an error if a variable is dereferenced while known to be null.
This is triggered by expressions like *ptr or ptr.field when the DFA determines ptr has a Nullable.Null state.
Parameters:
DFAConsequence* on The consequence containing the variable state (must be Nullable).
Loc loc The source location of the dereference.
void onEndOfScope(FuncDeclaration fd, ref const Loc loc);
Validates constraints at the end of a scope.
This checks if output parameters (like out or ref parameters) meet their guaranteed post-conditions. For example, if a function parameter is marked to guarantee a non-null output, this ensures the variable is actually non-null when the scope exits.
void onAssertIsFalse(ref DFALatticeRef lr, ref Loc loc);
Reports an error if an assertion is statically provable to be false.
If the DFA determines that the condition x in assert(x) is definitively false (e.g., assert(null) or assert(0) after analysis), it reports this logic error.
void onFunctionCallArgumentLessThan(DFAConsequence* c, ParameterDFAInfo* paramInfo, FuncDeclaration calling, ref Loc loc);
Reports an error if a function argument violates the callee's expectations.

Example Passing null to a function parameter marked as requiring non-null.