Runtime Bounds Checking and Safe Defaults
Effort: Small
Several runtime functions crash on edge cases instead of returning errors.
Issues
- `String.slice(str, start, len)` — crashes if start/len out of range (should return empty string)
- `Map.get(key, map)` — crashes if map is not a map (should return error tuple)
- `List.first([])` — should return nil, not crash
- `List.last([])` — should return nil, not crash
- `Enum.reduce([], fn)` — should handle empty list gracefully
- Map field access `user.name` — crashes with badkey if field doesn't exist (should return nil)
Solution
- Add guard clauses and fallback returns to all runtime functions
- Map field access in codegen: use `maps:get(Key, Map, nil)` instead of `maps:get(Key, Map)`
- Document which functions can return nil vs raise
Runtime Bounds Checking and Safe Defaults
Effort: Small
Several runtime functions crash on edge cases instead of returning errors.
Issues
Solution