You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: hand-written.md
+11-7Lines changed: 11 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -154,6 +154,14 @@ With [JEP-118](http://openjdk.java.net/jeps/118), parameter names can be stored
154
154
scala> val paramNames = classOf[Person].getConstructors.head.getParameters.toList
155
155
paramNames: List[java.lang.reflect.Parameter] = List(final java.lang.String name, final int age)
156
156
157
+
#### New representation and locking scope for local lazy vals
158
+
159
+
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)).
160
+
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.
162
+
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.
164
+
157
165
### Tooling improvements
158
166
159
167
#### New back end
@@ -346,18 +354,14 @@ While the adjustment to overloading resolution improves compatibility, there als
346
354
<console>:13: error: ambiguous reference to overloaded definition
347
355
348
356
349
-
### Inferred types for `val` (and `lazy val`)
357
+
### Inferred types for fields
350
358
351
-
[#5141](https://github.com/scala/scala/pull/5141) and [#5294](https://github.com/scala/scala/pull/5294) align type inference for `def`, `val`, and `lazy val`, fixing assorted corner cases and inconsistencies. As a result, the inferred type of a `val` or `lazy val` may change.
359
+
Type inference for `val`, and `lazy val` has been aligned with `def`, fixing assorted corner cases and inconsistencies ([#5141](https://github.com/scala/scala/pull/5141) and [#5294](https://github.com/scala/scala/pull/5294)). Concretely, when computing the type of an overriding field, the type of the overridden field is used used as expected type. As a result, the inferred type of a `val` or `lazy val` may change in Scala 2.12.
352
360
353
-
In particular, `implicit val`s that didn't need explicitly declared types before may need them now. (This is always good practice anyway.)
361
+
In particular, an `implicit val` that did not need an explicitly declared type in 2.11 may need one now. (This is always good practice anyway.)
354
362
355
363
You can get the old behavior with `-Xsource:2.11`. This may be useful for testing whether these changes are responsible if your code fails to compile.
356
364
357
-
[Lazy vals and objects](https://github.com/scala/scala/pull/5294) have been reworked, and those defined in methods now use a [more efficient representation](https://github.com/scala/scala/pull/5374) that allows synchronization on the holder of the `lazy val`, instead of the surrounding class (as in Dotty).
358
-
359
-
-- TODO: why is this in the "inferred types" section, why under "breaking changes"? This should go somewhere else.
360
-
361
365
### Changed syntax trees (affects macro and compiler plugin authors)
362
366
363
367
PR [#4794](https://github.com/scala/scala/pull/4749) changed the syntax trees for selections of statically accessible symbols. For example, a selection of `Predef` no longer has the shape `q"scala.this.Predef"` but simply `q"scala.Predef"`. Macros and compiler plugins matching on the old tree shape need to be adjusted.
0 commit comments