EngineHub / EngineHub/CommandHelper

[Feature request] Add cast function with sugared syntax

未关闭
#1,277 0 条评论 0 个 reaction 已指派 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 描述了一个新的 cast(mixed, classtype) 函数和带语法糖的 (type) 表达式语法,包括 ClassCastException 的行为以及一个类型检查示例。由于没有指定源文件、测试或入口点,请先定位现有的 integer、string、boolean 和 double 转换,以及表达式的 parser 和类型检查路径。完成的标准是两种形式都能转换为请求的类型,并按指定拒绝不兼容的值。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
compilers
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。