[chuck-users] a koan (and a bug request)

Robert Poor rdpoor at gmail.com
Mon Jan 25 00:56:08 EST 2010


Quiz: what will happen when the following code is run[*]?

=================
    class Trait {
        fun void announce() { <<< "I am generic." >>>; }
        fun void invoke() { announce(); }
    }
    class Legacy extends Trait {
        fun void announce() { <<< "I am legacy." >>>; }
    }
    class Lunacy extends Trait {
        public void announce() { <<< "I am lunacy." >>>; }
    }
    (new Legacy).invoke();
    (new Lunacy).invoke();
=================

If you predict that it prints:

    "I am legacy." : (string)
    "I am lunacy." : (string)

then here's a hint: there's a typo in the definition of Lunacy's announce()
method where it says "public void announce()..." instead of "fun void
announce()...".

If you predict that it gets a compiler error when it encounters the typo,
well, you'd be wrong there as well.  What happens instead is that it
compiles without any error messages, and the result is:

    "I am legacy." : (string)
    "I am generic." : (string)

It took me a LONG time to find this one (and an even longer time to boil it
down to a succinct example).  Will the powers that be please take this as a
request to beef up the parser?

Thanks.

- Rob

[*] in particular, chuck v 1.2.1.3 mac os x : intel.  I'm guessing that this
is platform independent, though...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20100124/d0c62678/attachment-0001.htm>


More information about the chuck-users mailing list