Skip to content

Runtime Type Tests #18

@DavePearce

Description

@DavePearce

Currently, there is no support for runtime type tests. There are two aspects:

  1. Type Tests. The test itself gets unwrapped into a tag equality test.
  2. Coercions. Subsequent uses of the variable are automatically coerced.

As a rough example, consider this Whiley function:

function get(int|null x) -> (int r):
   if x is int:
      return x
   else:
      return 0

This would be translated into this Java:

static BigInteger get(Union x) {
   if(x.isInt()) {
       return x.asBigInteger();
   } else {
       return BigInteger.ZERO;
   }
}

The need for the coercion should be evident from the target type of x at the variable access. Basically, we have an implicit coercion from int|null to int.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions