Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return null when casting to an incompatible reference type #1155

Closed
degory opened this issue Apr 3, 2024 · 0 comments · Fixed by #1156
Closed

Return null when casting to an incompatible reference type #1155

degory opened this issue Apr 3, 2024 · 0 comments · Fixed by #1156

Comments

@degory
Copy link
Owner

degory commented Apr 3, 2024

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?;
@degory degory changed the title Failed cast of reference types should return null Return null when casting to an incompatible reference type Apr 3, 2024
degory added a commit that referenced this issue Apr 3, 2024
Enhancements:
- Return null when casting to an incompatible reference type (closes #1155)
degory added a commit that referenced this issue Apr 3, 2024
Enhancements:
- Return null when casting to an incompatible reference type (closes #1155)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

1 participant