Search code examples
if-statementceylon

Check the type of an enumerated class


I have an enumerated abstract class:

shared abstract class Foo() of bar|baz {}

And a function that attempts to check if a Foo is not a bar:

shared void test(Foo foo) {
    if (!is bar foo) {

    }
}

I get the error

incorrect syntax: no viable alternative at token 'bar'

Solution

  • @gdejohn's answer is correct, but I would also note that it doesn't usually make much sense to directly refer to the type of an enumerated instance. Usually you would write the code like this:

    void test(Foo foo) {
        if (foo!=bar) {
            print("Not bar!");
        }
    }