Skip to content

Runtime bounds checking and safe defaults #58

@gregwinn

Description

@gregwinn

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/runtimeRuntime modules (winn_runtime.erl, stdlib)bugSomething isn't working

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions