Skip to content

Commit 8f46e6b

Browse files
committed
scala.js infer improvements
1 parent b77f54c commit 8f46e6b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

hand-written.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,27 @@ With [JEP-118](http://openjdk.java.net/jeps/118), parameter names can be stored
158158

159159
Local lazy vals and objects, i.e., those defined in methods, now use a more efficient representation (implemented in [#5294](https://github.com/scala/scala/pull/5294) and [#5374](https://github.com/scala/scala/pull/5374)).
160160

161-
In Scala 2.11, a local lazy val is encoded using two heap-allocated objects (one for the value, a second for the initialized flag), and initialization synchronizes on the enclosing class instance.
161+
In Scala 2.11, a local lazy val is encoded using two heap-allocated objects (one for the value, a second for the initialized flag), and initialization synchronizes on the enclosing class instance. With the new [representation for lambdas](#java-8-style-bytecode-for-lambdas) in 2.12, which emits the lambda body as a method in the enclosing class, this encoding can cause new deadlocks for lazy vals or objects defined in the lambda body.
162162

163-
This has been cleaned up by creating a single heap-allocated object that holds both the value and the initialized flag, and is at the same time used as initialization lock. A similar implementation already existed in Dotty.
163+
This has been fixed by creating a single heap-allocated object that holds both the value and the initialized flag, and is at the same time used as initialization lock. A similar implementation already existed in Dotty.
164+
165+
#### Better type inference for Scala.js
166+
167+
The [improved type inference for lambda parameters](#lambda-syntax-for-sam-types) also benefits `js.Function`s. For example, you can now write:
168+
169+
dom.window.requestAnimationFrame { now => // inferred as Double
170+
...
171+
}
172+
173+
without having to specify `(now: Double)` explicitly. In a similar spirit, the [new inference for overriding `val`s](#inferred-types-for-fields) allows to more easily implement Scala.js-defined JS traits with anonymous objects. For example:
174+
175+
@ScalaJSDefined
176+
trait SomeOptions extends js.Object {
177+
val width: Double | String // e.g., "300px"
178+
}
179+
val options = new SomeOptions {
180+
val width = 200 // implicitly converted from Int to the inferred Double | String
181+
}
164182

165183
### Tooling improvements
166184

0 commit comments

Comments
 (0)