Add support for cast(X, Y} #587
nielstron
started this conversation in
Ideas / Improvements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have seen many implementations awkwardly use typed assignments (a: X = Y) to implement type casts. Python does have a canonical way of doing type casts within expressions, cast. OpShin should support this.
The way this should be implemented is allowing the import of cast from typing in the typing import rewriter, and giving it a special polymorphic function type (basically return type = first argument). the function should check comparability of types, i.e. that X <= actual type or actual type <= X, similar to how typed assignments are handled in the aggressive type inferencer.
Beta Was this translation helpful? Give feedback.
All reactions