Skip to content

Add support for cast(X, Y} #585

@nielstron

Description

@nielstron

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions