EngineHub / EngineHub/CommandHelper

[Feature request] Add cast function with sugared syntax

Open
#1,277 0 comments 0 reactions 0 assignees View on GitHub
feature request
Dominant language
Java
Stars
128
Forks
70
PR merge metrics
No merged PRs in 30d

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.

Contributor guide

Open the contributing guide

Research direction

The issue describes a new cast(mixed, classtype) function and sugared (type) expression syntax, including ClassCastException behavior and a type-checking example. No source files, tests, or entry points are named, so first locate the existing integer, string, boolean, and double conversions and the parser/type-checking paths for expressions. Done means both forms cast to the requested type and reject incompatible values as specified.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.