[chuck-users] forward reference oddity

Robert Poor rdpoor at gmail.com
Fri Oct 2 18:39:25 EDT 2009


Here's another oddity.  The following file:
---------------------------------------
// file: ouroboros.ck
class Ouro {
     Boros @ boros;
     fun void set_boros(Boros boros) {
         <<< this.toString(), "set_boros(", boros.toString(), ")" >>>;
         boros @=> this.boros;
     }
}
class Boros {
     Ouro @ ouro;
     fun void set_ouro(Ouro ouro) {
         <<< this.toString(), "set_ouro(", ouro.toString(), ")" >>>;
         ouro @=> this.ouro;
     }
}
---------------------------------------
gets a compile-time error:
---------------------------------------
r% chuck ouroboros.ck
[ouroboros.ck]:line(5): class 'Boros' has no member 'toString'
[ouroboros.ck]: ...in function 'set_boros'
---------------------------------------
This is odd, since (AFAIK) toString() is defined on the Object class,  
and all classes inherit from Object.  If I remove the toString() call  
on boros as below, it compiles without error.  Note chat ChucK has no  
problem compiling ouro.toString() in function 'set_ouro':
---------------------------------------
// file: ouroboros.ck
class Ouro {
     Boros @ boros;
     fun void set_boros(Boros boros) {
         <<< this.toString(), "set_boros(", boros, ")" >>>;
         boros @=> this.boros;
     }
}
class Boros {
     Ouro @ ouro;
     fun void set_ouro(Ouro ouro) {
         <<< this.toString(), "set_ouro(", ouro.toString(), ")" >>>;
         ouro @=> this.ouro;
     }
}
---------------------------------------
Is this because Boros is a forward reference?  And is this not a bug?

- Rob



More information about the chuck-users mailing list