Skip to content

Fix #635: Remove extra code blocks in SIP-25 #636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions sips/pending/_posts/2016-01-11-static-members.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ There is no special syntax proposed to access these members, they are accessed a

For example:

```scala
{% highlight scala %}
class Foo

Expand All @@ -42,12 +41,10 @@ object Foo {
println(Foo.x)
println(Foo.bar(12))
{% endhighlight %}
```

Intuitively, the presence of the `@static` annotation ensures that a field/method is declared as a static member of the companion class.
For the JVM, the above would therefore look to other Java code as if it had been declared with the following Java code:

```java
{% highlight java %}
class Foo {
public static int x = 5;
Expand All @@ -56,12 +53,10 @@ class Foo {
}
}
{% endhighlight %}
```

In Scala.js, the `@static` annotation has no semantic effect in Scala objects, as they are not visible from JavaScript anyway (it could be used for optimizations).
It has a semantic effect on Scala.js-defined JS classes, for example:

```scala
{% highlight scala %}
@ScalaJSDefined
class Foo extends js.Object
Expand All @@ -72,11 +67,9 @@ object Foo extends js.Object {
@static def bar(y: Int): Int = x + y
}
{% endhighlight %}
```

would look to JavaScript code as if it had been declared with the following JavaScript code:

```javascript
{% highlight javascript %}
class Foo extends Object {
static bar(y) {
Expand All @@ -85,13 +78,11 @@ class Foo extends Object {
}
Foo.x = 5; // in ES6, there is no declarative syntax for static fields yet
{% endhighlight %}
```

## Comparison with mirror classes ##

Scalac currently generates static forwarders for fields and methods in top-level objects:

```scala
{% highlight scala %}
object O {
val d = 1
Expand All @@ -100,7 +91,6 @@ object O {
}
}
{% endhighlight %}
```

Under the proposed scheme users will be able to opt-in to have the field `f` defined in the inner object `I` emited as a static field.
In case `O.d` is annotated with `@static` the field will be crated as a static field `d` in `class O`.
Expand Down