TeamShadow / shadow

Reference compiler for the Shadow programming language.
http://shadow-language.org/
Apache License 2.0
12 stars 8 forks source link

Changed inner classes to "static" #64

Closed bwittman closed 7 years ago

bwittman commented 7 years ago

This commit makes all inner classes behave like "static" inner classes in Java and all inner classes in C#: They are not associated with a particular outer class object and thus are unable to access the members of an outer class without referencing a particular outer class object.

From the perspective of access, inner classes still have the right to read/write outer class fields and private or protected methods, provided that they have a reference through which to access such fields.

This change was made to simplify the back end and to reduce the number of references from inner classes to outer classes, which are an abundant source of circular references, never wise in a system that uses reference counting for primary garbage collection.

One annoyance is that syntax has become more cluttered, requiring more angle brackets with more type parameters and arguments for inner classes. However, a shorthand approach for this problem is coming in future commits.

Also, in cases where access to the outer class is desired (such as an iterator), a reference to the outer class is often passed through the inner class constructor.

Note: Although it should have been a separate series of commits, changes to the standard library and to the definition of arrays in these commits make it so that most containers with a size property now also have a sizeLong property, which gives the number of elements in the container as a long. In all of these cases, the sizeLong property is now the fundamental size, and size is a derived property cast to an int for convenience.