degory / ghul

compiler for the ghūl programming language
https://ghul.dev
GNU Affero General Public License v3.0
4 stars 0 forks source link

Return null when casting to an incompatible reference type #1155

Closed degory closed 7 months ago

degory commented 7 months ago

When casting an object to a reference type that it does not implement or inherit from, the cast operation should return a null reference instead of throwing an exception.

let is_iterable = [1, 2, 3, 4, 5];
let maybe_iterable = cast Iterable[int](is_iterable);
assert maybe_iterable? /\ isa Iterable[int](maybe_iterable);

let not_iterable = object();
maybe_iterable = cast Iterable[int](not_iterable);

assert !maybe_iterable?;