Skip to content

Commit e7982e7

Browse files
committed
fix formatting
1 parent 6ab758f commit e7982e7

File tree

2 files changed

+32
-39
lines changed

2 files changed

+32
-39
lines changed

news/_posts/2016-04-11-release-notes-2.12.0-M4.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,34 +60,30 @@ The work on the new optimizer is still ongoing. You can track it in the [scala-
6060
#### SAM types
6161
As of [#4971](https://github.com/scala/scala/pull/4971), we treat Single Abstract Method types in the same way as our built-in FunctionN classes. This means overloading resolution has more contenders to choose from, making type inference less effective. Here's an example:
6262

63-
```scala
64-
class C[V] {
65-
def sort(cmp: java.util.Comparator[V]): C[V] = ???
66-
def sort(cmp: (V, V) => Int): C[V] = sort(
67-
new java.util.Comparator[V] {
68-
def compare(a: V, b: V): Int = cmp(a, b)
69-
})
70-
}
71-
72-
(new C[Int]) sort (_ - _) // error
73-
(new C[Int]) sort ((_ - _): java.util.Comparator[Int]) // ok
74-
(new C[Int]) sort ((a: Int, b: Int) => a - b) // ok
75-
```
63+
class C[V] {
64+
def sort(cmp: java.util.Comparator[V]): C[V] = ???
65+
def sort(cmp: (V, V) => Int): C[V] = sort(
66+
new java.util.Comparator[V] {
67+
def compare(a: V, b: V): Int = cmp(a, b)
68+
})
69+
}
70+
71+
(new C[Int]) sort (_ - _) // error
72+
(new C[Int]) sort ((_ - _): java.util.Comparator[Int]) // ok
73+
(new C[Int]) sort ((a: Int, b: Int) => a - b) // ok
7674

7775
The first attempt fails because the type checker cannot infer the types for `_ - _`'s arguments anymore.
7876
Type inference in this scenario only works when we can narrow the overloads down to one before type checking the arguments the methods are applied to. When a function is passed as an argument to an overloaded method, we do this by considering the "shape" of the function (essentially, its arity). Now that `Comparator[?]` and `(?, ?) => ?` are both considered functions of arity two, our clever scheme breaks down and the programmer must either select an overload (second application) or make the argument types explicit (last application, which resolves to the `Function2` overload).
7977

8078
Finally, implicit conversion of SAM types to Function types won't kick in anymore, since the compiler does this conversion itself first:
8179

82-
```scala
83-
trait MySam { def apply(x: Int): String }
80+
trait MySam { def apply(x: Int): String }
8481

85-
implicit def unused(fun: Int => String): MySam
86-
= new MySam { def apply(x: Int) = fun(x) }
82+
implicit def unused(fun: Int => String): MySam
83+
= new MySam { def apply(x: Int) = fun(x) }
8784

88-
// uses sam conversion, not the `unused` implicit
89-
val sammy: MySam = _.toString
90-
```
85+
// uses sam conversion, not the `unused` implicit
86+
val sammy: MySam = _.toString
9187

9288
#### Changed syntax trees (affects macro and compiler plugin authors)
9389

news/_posts/2016-06-29-release-notes-2.12.0-M5.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ We are happy to announce the availability of Scala 2.12.0-M5!
99
Notable changes in M5
1010
([see here](https://github.com/scala/scala/pulls?utf8=%E2%9C%93&q=milestone%3A2.12.0-M5%20label%3Arelease-notes)
1111
for a more extensive list):
12+
1213
- [#5251](https://github.com/scala/scala/pull/5251): concrete trait methods are compiled to a
1314
static method (in the interface classfile) containing the actual implementation, and a default
1415
method forwards that to the static one.
@@ -82,34 +83,30 @@ The work on the new optimizer is still ongoing. You can track it in the [scala-
8283
#### SAM types
8384
As of [#4971](https://github.com/scala/scala/pull/4971), we treat Single Abstract Method types in the same way as our built-in FunctionN classes. This means overloading resolution has more contenders to choose from, making type inference less effective. Here's an example:
8485

85-
```scala
86-
class C[V] {
87-
def sort(cmp: java.util.Comparator[V]): C[V] = ???
88-
def sort(cmp: (V, V) => Int): C[V] = sort(
89-
new java.util.Comparator[V] {
90-
def compare(a: V, b: V): Int = cmp(a, b)
91-
})
92-
}
86+
class C[V] {
87+
def sort(cmp: java.util.Comparator[V]): C[V] = ???
88+
def sort(cmp: (V, V) => Int): C[V] = sort(
89+
new java.util.Comparator[V] {
90+
def compare(a: V, b: V): Int = cmp(a, b)
91+
})
92+
}
9393

94-
(new C[Int]) sort (_ - _) // error
95-
(new C[Int]) sort ((_ - _): java.util.Comparator[Int]) // ok
96-
(new C[Int]) sort ((a: Int, b: Int) => a - b) // ok
97-
```
94+
(new C[Int]) sort (_ - _) // error
95+
(new C[Int]) sort ((_ - _): java.util.Comparator[Int]) // ok
96+
(new C[Int]) sort ((a: Int, b: Int) => a - b) // ok
9897

9998
The first attempt fails because the type checker cannot infer the types for `_ - _`'s arguments anymore.
10099
Type inference in this scenario only works when we can narrow the overloads down to one before type checking the arguments the methods are applied to. When a function is passed as an argument to an overloaded method, we do this by considering the "shape" of the function (essentially, its arity). Now that `Comparator[?]` and `(?, ?) => ?` are both considered functions of arity two, our clever scheme breaks down and the programmer must either select an overload (second application) or make the argument types explicit (last application, which resolves to the `Function2` overload).
101100

102101
Finally, implicit conversion of SAM types to Function types won't kick in anymore, since the compiler does this conversion itself first:
103102

104-
```scala
105-
trait MySam { def apply(x: Int): String }
103+
trait MySam { def apply(x: Int): String }
106104

107-
implicit def unused(fun: Int => String): MySam
108-
= new MySam { def apply(x: Int) = fun(x) }
105+
implicit def unused(fun: Int => String): MySam
106+
= new MySam { def apply(x: Int) = fun(x) }
109107

110-
// uses sam conversion, not the `unused` implicit
111-
val sammy: MySam = _.toString
112-
```
108+
// uses sam conversion, not the `unused` implicit
109+
val sammy: MySam = _.toString
113110

114111
#### Changed syntax trees (affects macro and compiler plugin authors)
115112

0 commit comments

Comments
 (0)