LogoMist

Semantic Analysis

Class field initialization verification and the GetMutability analysis system.

The semantic checker (semantics.rs) performs class field initialization analysis. When a class has a constructor, it verifies that every declared field is mutated (directly or indirectly via method calls) within the constructor body.

Field Initialization

The primary semantic check ensures all class fields are initialized in the constructor:

class Player
{
    i32 health;
    str& name;

    pub constructor(str& name)
    {
        self.name = name;
        // Error: field 'health' is uninitialized
    }
}

How It Works

The GetMutability trait tracks which identifiers are mutated:

  1. Collects all identifiers that get &mut references
  2. Tracks self.field = value patterns
  3. Follows method calls that might initialize fields (transitively)
  4. Ensures all conditional branches initialize the same fields (intersection semantics)
  5. super assignments count for _super field initialization

If any field is uninitialized after the analysis, a SemanticError is reported with the field's source position.

On this page