Compile Time Changes

The following changes have been made that affect the CM language, or how it compiles:

enum toS methods

In 13.5, enum types automatically implement a toS function, unless the -toS property is specified on the declaration. The toS method on generated box classes will refer to the unboxed toS, so the toS output on enum box classes and their unboxed equivalents will now match (by default).

Thus, if you want to implement your own toS for an enum, all you need to do is add -toS to the enum declaration and write your own toS function.

public enum foo : field access {
    foo;
    bar;
    baz;
};


/**
 * This is a trivial toS function so it can be removed in 13.5
 */
public str toS(foo f) {
    switch (f) {
      case foo: return "foo";
      case bar: return "bar";
      case baz: return "baz";
    }
}

public enum bar : field access, -toS {
    foo;
    bar;
    baz;
};

/**
 * This is a non-trivial toS function; add the -toS property to the enum declaration
 */
public str toS(bar f) {
    switch (f) {
      case foo: return "bar: foo";
      case bar: return "bar: bar";
      case baz: return "bar: baz";
    }
}

seq.setCount is now marked unsafe

The setCount function on sequences (such as int[]) is now considered "unsafe" and should not be used where alternative solutions are available.

  • If you want to clear a sequence, use clear() instead of setCount(0)
  • If you want to truncate a sequence (reduce the number of items), use truncate(n) instead of setCount(n)
  • If you want to allocate a sequence and immediately setCount (often needed when interfacing with foreign code), use the new constructor argument int[] foo(count=128);. Note that an unnamed argument specifies capacity, not count.