Skip to content

Commit af0572f

Browse files
committed
Incorporate feedback from @lrytz
1 parent a2e89fb commit af0572f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

sips/pending/_posts/2016-01-01-static-members.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ Foo.x = 5; // in ES6, there is no declarative syntax for static fields yet
8787
{% endhighlight %}
8888
```
8989

90+
## Comparisson with mirror classes ##
91+
92+
Scalac currently generates static forwarders for fields and methods in top-level objects:
93+
94+
```scala
95+
{% highlight scala %}
96+
object O {
97+
val d = 1
98+
object I {
99+
val f = 1
100+
}
101+
}
102+
{% endhighlight %}
103+
```
104+
105+
Under proposed scheme users will be able to opt-in to have field `f` on inner object `I` generated as static field.
106+
90107
## Restrictions ##
91108

92109
The following rules ensure that method can be correctly compiled into static member on both JVM and JavaScript:
@@ -95,7 +112,7 @@ The following rules ensure that method can be correctly compiled into static mem
95112

96113
2. The fields annotated with `@static` should preceed any non-`@static` fields. This ensures that we do not introduce surprises for users in initialization order.
97114

98-
3. The right hand side of a method or field annotated with `@static` can only refer to members of globally accessible objects and `@static` members. In particular, for non-static objects `this` is not accesible. `super` is never accessible.
115+
3. The right hand side of a method or field annotated with `@static` can only refer to top-level classes, members of globally accessible objects and `@static` members. In particular, for non-static objects `this` is not accesible. `super` is never accessible.
99116

100117
4. If a member `foo` of an `object C` is annotated with `@static`, the companion class `C` is not allowed to define term members with name `foo`.
101118

0 commit comments

Comments
 (0)