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: content/polymorphic-eta-expansion.md
+17-6Lines changed: 17 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -388,18 +388,29 @@ If it doesn't do so "by construction", this section should present the ideas of
388
388
389
389
This section should also argue to what extent backward source compatibility is preserved. In particular, it should show that it doesn't alter the semantics of existing valid programs. -->
390
390
391
-
There are two cases:
391
+
#### Binary and TASTy
392
392
393
-
#### There is a (potentially partially applied) method taking type parameters used without an expected type
393
+
As this proposal never generates code that couldn't have been written before, these changes are binary and TASTy compatible.
394
394
395
-
In this case we are not sure about compatibility, and help is welcome
395
+
#### Source
396
396
397
+
This proposal conserves source compatibility when an expected type is present, since either the behaviour is the same, or the code did not compile before.
397
398
398
-
#### Otherwise
399
+
This proposal breaks source compatibility only when there is no expected type, in this regard it is essentially a change in type inference, and therefore has all the usual repercussions of changing type inference, for example:
399
400
400
-
As long as (potentially partially applied) methods taking type arguments are not used in places without an expected type, these changes are source, binary and TASTy compatible.
401
+
```scala
402
+
deffoo[T](x: T):T= x
403
+
valvoo= foo // was Any => Any is now [T] => T => T
404
+
valy= voo(5) // was Any is now Int
401
405
402
-
This is a consequence of this feature not changing current behaviour for cases that did compile before, and adding new behaviour for cases that did not compile before.
406
+
deflookFor[T](x: T)(usingu: T):T= u
407
+
lookFor(foo) // was searching for Any => Any, is now searching for [T] => T => T
408
+
// This change in search can find different instances, and thus potentially wildly different behaviour !
409
+
```
410
+
411
+
While these examples might seem damming, this is the case every time we change type inference.
412
+
413
+
**Note:** All of this disappears if we change `val voo` to `val voo: Any => Any`, this is the reason it is recommended for library authors to always provide explicit types for all public members.
0 commit comments