@@ -74,11 +74,11 @@ It compiles with Scala 2, but Scala 3 produces the following errors:
74
74
75
75
~~~
76
76
[error] -- [E043] Type Error:
77
- [error] 5 | def f(foo: Foo[_]): Unit // Warning with Scala 3
77
+ [error] 5 | def f(foo: Foo[_]): Unit // Error with Scala 3
78
78
[error] | ^^^^^^
79
79
[error] |unreducible application of higher-kinded type Example.this.Foo to wildcard arguments
80
80
[error] -- [E043] Type Error:
81
- [error] 6 | def g(foos: Seq[Foo[_]]): Unit // Warning with Scala 3
81
+ [error] 6 | def g(foos: Seq[Foo[_]]): Unit // Error with Scala 3
82
82
[error] | ^^^^^^
83
83
[error] |unreducible application of higher-kinded type Example.this.Foo to wildcard arguments
84
84
~~~
@@ -95,27 +95,17 @@ In the case of the function `f`, we can change its signature to take a type para
95
95
96
96
The second function, ` g ` , requires more work. We want to accept collections containing
97
97
values of type ` Foo[A] ` with possibly different types for the parameter ` A ` . To achieve
98
- this, we create a wrapper type that models the type parameter as a type member instead:
98
+ this, we create a wrapper class. The fact that the wrapper is a class and not an abstract
99
+ type member makes it possible to apply a wildcard type argument to it:
99
100
100
101
~~~ scala
101
- // Wrapper type
102
- trait SomeFoo {
103
- type T
104
- def value : Foo [T ]
105
- }
106
-
107
- // Construct a value of type `SomeFoo`
108
- def SomeFoo [A ](foo : Foo [A ]): SomeFoo =
109
- new SomeFoo {
110
- type T = A
111
- def value = foo
112
- }
113
-
114
- def g (foos : Seq [SomeFoo ]): Unit // Compiles with both Scala 2 and Scala 3
102
+ // Wrapper class
103
+ class FooWrapper [A ](val value : Foo [A ])
104
+
105
+ def g (foos : Seq [FooWrapper [_]]): Unit // Compiles with both Scala 2 and Scala 3
115
106
~~~
116
107
117
- Users will have to explicitly wrap their ` Foo ` values into ` SomeFoo ` by calling the
118
- corresponding constructor.
108
+ Users will have to explicitly wrap their ` Foo ` values into the ` FooWrapper ` class.
119
109
120
110
### Other incompatibilities
121
111
0 commit comments