Docs rewrite
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
---
|
||||
title: Semantic Analysis
|
||||
description: Class field initialization verification and the GetMutability analysis system.
|
||||
icon: SearchCheck
|
||||
---
|
||||
|
||||
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:
|
||||
|
||||
```mist
|
||||
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.
|
||||
Reference in New Issue
Block a user