I reported a number of bugs in the lookup behavior of the first compiler2beta release, and they all appear to have been fixed in the second beta. But the second beta introduces a new change.
Prior to compiler2beta 2, nested classes only had access to the global scope, but in compiler2beta 2, they also have access to any modules that contain their containing classes. This seems like a sensible change, but it does result in changes in behavior for existing programs. And since -O0 keeps the old behavior, it even means a change in behavior depending on optimization level.
import Toybox.Lang; import Toybox.Test; const K = 1; module M { const K = 2; class Outer { class Inner { function f() as Number { return K; } } } } // Passes prior to compiler2beta 2, or // when compiled with -O0. // Fails with compiler2beta 2 at -O1 and -O2 (:test) function compiler2beta2NestedLookup(logger as Logger) as Boolean { var inner = new M.Outer.Inner(); var x = inner.f(); logger.debug("x = " + x.toString()); return x == 1; }
Again, the new behavior makes sense, but if intentional, it should be documented; also -O0 should be fixed to produce the same result as -O1 and -O2.