Quiz: what will happen when the following code is run[*]?<div><div><br></div><div>=================</div><div><div> class Trait {</div><div> fun void announce() { <<< "I am generic." >>>; }</div>
<div> fun void invoke() { announce(); }</div><div> }</div><div> class Legacy extends Trait {</div><div> fun void announce() { <<< "I am legacy." >>>; }</div><div> }</div>
<div> class Lunacy extends Trait {</div><div> public void announce() { <<< "I am lunacy." >>>; }</div><div> }</div><div> (new Legacy).invoke();</div><div> (new Lunacy).invoke();</div>
<div><div>=================</div><div><br></div><div>If you predict that it prints:</div><div><div><br></div><div> "I am legacy." : (string)</div><div> "I am lunacy." : (string)</div><div><br></div>
<div>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()...". </div><div><br></div>
<div>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:</div><div><br>
</div><div><div> "I am legacy." : (string)</div><div> "I am generic." : (string)</div><div><br></div><div>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?</div>
<div><br></div><div>Thanks.</div><div><br></div><div>- Rob</div><div><br></div><div>[*] in particular, chuck v 1.2.1.3 mac os x : intel. I'm guessing that this is platform independent, though...</div><div><br></div></div>
</div><div></div></div></div></div>