NetLogo / Tortoise

Compiler and runtime engine for NetLogo models that runs in JavaScript 🐢
https://netlogoweb.org
Other
56 stars 27 forks source link

Error on foreign breed var access #239

Closed TheBizzle closed 2 years ago

TheBizzle commented 2 years ago

See #237 for the reported bug.

Seeking review from @LaCuneta, since this is a substantial change, whereby foreign breed vars register with the VariableManager to throw errors when accessed.

A test was added for this in https://github.com/NetLogo/NetLogo/commit/9125b7b1e0e7775e132af694da0e032725fd90c4.

TheBizzle commented 2 years ago

Hmm... I need to think on this.... :thinking:

I like the idea of moving this error messaging to the middle layer. But the only obvious way that I'm seeing of integrating with what you've got there would require adding a small performance overhead to every turtle/link variable access, just to cover this very niche case of trying to reference a variable that belongs to another breed (which, honestly, in a better version of NetLogo, would simply be caught at compile-time).

One thing I like about 22eb608 is that there's merely an overhead at the time of turtle creation (exactly once per turtle), rather than at the time of every variable access (0-1 jillion times per turtle).

I'm going to ponder other options for handling this in the middle layer, and return to this soon.

TheBizzle commented 2 years ago

Alright! Thanks for letting me know about the existing stuff in the middle layer; it helped me to come up with a fix that I'm happier with. :sunglasses: :+1:

Assuming this passes the tests, I think it should be ready for a re-review!