Skip to content

[Feature request] Add cast function with sugared syntax #1277

Open
@Pieter12345

Description

@Pieter12345

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestNew functionality that doesn't exist yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions