Skip to content

Commit f5f339b

Browse files
committed
docs: update nullable type handling and examples in reference documentation
- Removed non-null assertion examples from nullable types documentation to emphasize safe call usage. - Updated design documentation to reflect the removal of non-null assertion from nullable types description. - Modified object model documentation to replace non-null assertions with safe call alternatives in casting examples, enhancing clarity on safe operations.
1 parent 3ec4d32 commit f5f339b

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

docs/reference/builtin_types.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ val hash: Int = greeting.GetHash()
3636
3737
Any primitive type can be made nullable by appending `?` (e.g., `Int?`, `String?`). Nullable types are passed by reference and can hold either a value or `null`.
3838

39-
**Important**: You cannot directly call methods on nullable types using `.` - you must use the safe call operator `?.` or non-null assertion `!!`.
39+
**Important**: You cannot directly call methods on nullable types using `.` - you must use the safe call operator `?.`.
4040

4141
```ovum
4242
val nullableString: String? = "Hello"
4343
// val length: Int = nullableString.Length() // ERROR: Cannot call method directly on nullable
4444
val safeLength: Int = nullableString?.Length() ?: 0 // Correct: Use safe call
45-
val forcedLength: Int = nullableString!!.Length() // Correct: Use non-null assertion
4645
```
4746

4847
## Array Types

docs/reference/design.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Ovum's core design principles center around:
1616
## Key Design Points
1717

1818
* **Strong static typing** with **immutability by default** (`var` required for mutation).
19-
* **Nullable types** and Kotlin-style null-handling: `Type?`, safe calls `?.`, Elvis `?:`, non-null assertion `!!`.
19+
* **Nullable types** and Kotlin-style null-handling: `Type?`, safe calls `?.`, Elvis `?:`.
2020
* **Pure functions** (no side effects, VM-level result caching).
2121
* **Classes & interfaces**
2222

docs/reference/object_model.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Point implements IComparable {
6868
6969
public override fun IsLess(other: Object): Bool {
7070
if (!(other is Point)) return false
71-
val p: Point = (other as Point)!!
71+
val p: Point = (other as Point) ?: Point(0, 0)
7272
if (this.X != p.X) return this.X < p.X
7373
return this.Y < p.Y
7474
}
@@ -289,13 +289,13 @@ val comparable: IComparable = point // Upcast to interface
289289
290290
// Downcasting with type test
291291
if (obj is Point) {
292-
val p: Point = (obj as Point)!! // Safe after type test
292+
val p: Point = (obj as Point) ?: Point(0, 0)
293293
sys::Print("Point: " + p.ToString())
294294
}
295295
296296
// Type test operator
297297
if (shape is ColoredRectangle) {
298-
val rect: ColoredRectangle = (shape as ColoredRectangle)!!
298+
val rect: ColoredRectangle = (shape as ColoredRectangle) ?: ColoredRectangle(0, 0, "red")
299299
sys::Print("Rectangle color: " + rect.GetColor())
300300
}
301301
```
@@ -383,7 +383,7 @@ class ResourceManager {
383383

384384
**Type Safety:**
385385
- Use type tests before casting (`is` before `as`)
386-
- Prefer safe operations (`?.` and `?:` over `!!`)
386+
- Prefer safe operations
387387
- Handle nullable types properly
388388

389389
```ovum
@@ -395,7 +395,7 @@ interface IWritable { fun Write(content: String): Void }
395395
fun SafeProcessObject(obj: Object?): Void {
396396
val result: String = obj?.ToString() ?: "null"
397397
if (obj is Person) {
398-
val person: Person = (obj as Person)!!
398+
val person: Person = (obj as Person) ?: Person("Unknown")
399399
sys::Print("Person: " + person.ToString())
400400
}
401401
}

0 commit comments

Comments
 (0)