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

[Feature request] Add cast function with sugared syntax #1277

Open
Pieter12345 opened this issue Mar 20, 2021 · 0 comments
Open

[Feature request] Add cast function with sugared syntax #1277

Pieter12345 opened this issue Mar 20, 2021 · 0 comments
Labels
feature request New functionality that doesn't exist yet

Comments

@Pieter12345
Copy link
Contributor

Problem

MethodScript currently does not have a method to cast to any desired type. This makes it impossible to fully statically type programs such as:

mixed @a = ...;
if(@a instanceof array) {
  array @arr = @a; // Typecheck error, need to insert a cast.
}

Proposed solution

  • Add a cast(mixed, classtype) function that casts the given mixed to the given classtype, or throws a ClassCastException when it can't.
  • Add (type) expression syntax that compiles to cast(expression, type).

Note that MethodScript currently does have integer(mixed), string(mixed), boolean(mixed) and double(mixed) that all cast to one specific type.

@Pieter12345 Pieter12345 added the feature request New functionality that doesn't exist yet label Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New functionality that doesn't exist yet
Projects
None yet
Development

No branches or pull requests

1 participant