EngineHub / EngineHub/CommandHelper

[Feature request] Add cast function with sugared syntax

Ouverte
#1,277 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
feature request
Langage dominant
Java
Étoiles
128
Forks
70
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

# 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:
```java
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.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.