Skip to content

Commit b7f4381

Browse files
committed
Rework compatibility section
1 parent 9bf1613 commit b7f4381

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

content/polymorphic-eta-expansion.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,18 +388,29 @@ If it doesn't do so "by construction", this section should present the ideas of
388388
389389
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. -->
390390

391-
There are two cases:
391+
#### Binary and TASTy
392392

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.
394394

395-
In this case we are not sure about compatibility, and help is welcome
395+
#### Source
396396

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.
397398

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:
399400

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+
def foo[T](x: T): T = x
403+
val voo = foo // was Any => Any is now [T] => T => T
404+
val y = voo(5) // was Any is now Int
401405

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+
def lookFor[T](x: T)(using u: 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.
403414

404415
### Restrictions
405416

0 commit comments

Comments
 (0)