Skip to content
  • Tom Almeida's avatar
    feat: Print an error when attempting to assign to a string index · 42e40e90
    Tom Almeida authored and AdminXVII's avatar AdminXVII committed
    Why is this needed?
    Well, at the moment nothing happens when the user tries something along
    the lines of `let some_string[3] = 'v'`, even though we don't allow it.
    The variable itself doesn't change, and we don't print any errors.
    This patch just makes the function that would assign return an error
    instead of silently failing.
    
    Why not implement modifying strings by index?
    Sure, we could do that, but it's not quite as obvious as it seems. We
    support utf8 strings, so modifying the `i`th byte obviously doesn't
    work, and could potentially make the string invalid. Another option
    would be to set the `i`th character to whatever is passed in. This is
    fine in theory, but it would be an `O(N)` operation in the average
    case, and we'd have to shuffle all the following chars either further up
    or further down the string.
    While this may be a desirable ability to eventually have, it will
    require significantly more work and thought around strings in ion than
    simply returning an error.
    42e40e90