EngineHub / EngineHub/CommandHelper

[Feature request] Add cast function with sugared syntax

Abierto
#1,277 0 comentarios 0 reacciones 0 asignados Ver en GitHub
feature request
Lenguaje dominante
Java
Estrellas
128
Forks
70
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

# 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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.