Skip to content

Commit 25b84a9

Browse files
committed
Flesh out migration discussion
+ fix tests added by rebase
1 parent ce73a94 commit 25b84a9

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

docs/docs/reference/witnesses/discussion.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,19 @@ The witness proposal consists of two main parts:
1616

1717
New and old syntax would co-exist initially. Rewrite rules could rewrite old syntax to new automatically. This is trivial in the case of implicit parameters and implicit function types. It is a bit more involved in the case of implicit definitions, since more extensive pattern matching is required to recognize a definition that can be rewritten to a witness.
1818

19-
The third part (replacing existing implicits) should be adopted well after the first two parts
20-
are implemented. Alias and abstract witnesses could be introduced together with the other witness definitions, but could also come later.
19+
To make gradual change possible, we allow the new `with` application syntax also for
20+
old style implicit parameters.
21+
22+
One tricky question concerns context bounds. During the migration period, should they map to old style implicit parameters or new style context parameters? Mapping them to context parameters could break things in difficult to diagnose ways since then an explicit argument for a context bound would be treated as a type error, or, in the worst case, would be constructed as an argument for an `apply` of the result of method with the
23+
context bound. Also, it would remove context bounds from the common subset that is
24+
treated the same in Scala 2 and 3. We therefore opt to map context bounds to old style implicit parameters for the time being. In the future, migrating context bounds implies a three-step process:
25+
26+
- Step 1: Deprecate passing arguments to evidence parameters defined by context bounds
27+
directly. All such parameters should be passed with `with`.
28+
- Step 2: Remove ability to pass context bound arguments directly.
29+
- Step 3: Map context bounds to context parameters.
30+
31+
The third part (replacing existing implicits) should be adopted well after the first two parts are implemented. Alias and abstract witnesses could be introduced together with the other witness definitions, but could also come later.
2132

2233
## Discussion
2334

tests/pos/case-getters.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
case class Foo(x: 1, y: implicit Int => Int)
1+
case class Foo(x: 1, y: Int |=> Int)
22
object Test {
3-
val f = Foo(1, implicit (i: Int) => i)
3+
val f = Foo(1, (i: Int) |=> i)
44
val fx1: 1 = f.x
55
val fx2: 1 = f._1
6-
val fy1: Int = f.y(1)
7-
val fy2: Int = f._2(1)
6+
val fy1: Int = f.y with 1
7+
val fy2: Int = f._2 with 1
88
}

tests/run/implicit-shortcut-bridge.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
abstract class A[T] {
22
def foo: T
33
}
4-
class B extends A[implicit Int => Int] {
4+
class B extends A[Int |=> Int] {
55
// No bridge needed for foo$direct
6-
def foo: implicit Int => Int = 1
6+
def foo: Int |=> Int = 1
77
}
88

9-
abstract class X[T] extends A[implicit T => T] {
10-
def foo: implicit T => T
9+
abstract class X[T] extends A[T |=> T] {
10+
def foo: T |=> T
1111
}
1212

1313
class Y extends X[Int] {
14-
def foo: implicit Int => Int = 1
14+
def foo: Int |=> Int = 1
1515
}
1616

1717
object Test {

0 commit comments

Comments
 (0)