EngineHub / EngineHub/CommandHelper

[Feature request] Add cast function with sugared syntax

オープン
#1,277 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
feature request
主要言語
Java
スター
128
フォーク
70
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。