NetLogo / Tortoise

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

Compiler issue: Turtle breeds accessing non-breed variables #237

Closed CIVITAS-John closed 2 years ago

CIVITAS-John commented 2 years ago

Hi,

This issue is proposed by @jiajia06403. Here is my reproduction:

breed [ tests1 test1 ]
breed [ tests2 test2 ]

tests1-own [ my-variable ]

to setup
  clear-all
  create-tests1 1 [ ]
  create-tests2 1 [ ]
  ask turtles [ print my-variable ]
end

Please note the different behavior between NetLogo and NetLogo Web. Specifically, if we assign my-variable for each turtle, in NLW both will work (but essentially still deviant from NetLogo Desktop behavior). Otherwise, my-variable would simply become undefined (!) result in random error messages when mistakenly used elsewhere.

Doing a runtime check on breed-own variables might be expensive. Could we implement a static check?