CommandHelper
CommandHelper copied to clipboard
[Feature request] Add cast function with sugared syntax
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:
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 aClassCastExceptionwhen it can't. - Add
(type) expressionsyntax that compiles tocast(expression, type).
Note that MethodScript currently does have integer(mixed), string(mixed), boolean(mixed) and double(mixed) that all cast to one specific type.