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
The [Scala 3 migration compilation](tooling-migration-mode.html) can automatically disambiguate the code by replacing `println(x)` with `println(this.x)`.
75
-
{% endtab %}
76
-
{% endtabs %}
77
77
78
78
## Non-private Constructor In Private Class
79
79
80
80
The Scala 3 compiler requires the constructor of private classes to be private.
81
81
82
-
{% tabs scala-3-constructor_1 %}
83
-
{% tab 'Scala 3 Only' %}
82
+
{% tabs scala-2-constructor_1 %}
83
+
{% tab 'Scala 2 Only' %}
84
84
For instance, in the example:
85
85
86
86
~~~scala
87
87
packagefoo
88
88
89
89
privateclassBarprivate[foo] () {}
90
90
~~~
91
+
{% endtab %}
92
+
{% endtabs %}
91
93
92
-
The error message is:
93
-
~~~text
94
+
If you try to compile in scala 3 you should get the following error message:
| non-private constructor Bar in class Bar refers to private class Bar
98
100
| in its type signature (): foo.Foo.Bar
99
-
~~~
101
+
{% endhighlight %}
100
102
101
103
The [Scala 3 migration compilation](tooling-migration-mode.html) warns about this but no automatic rewrite is provided.
102
104
103
105
The solution is to make the constructor private, since the class is private.
104
-
{% endtab %}
105
-
{% endtabs %}
106
106
107
107
## Abstract Override
108
108
@@ -149,7 +149,6 @@ Foo.tupled((2, false))
149
149
{% tab 'Scala 3' for=companion_1 %}
150
150
151
151
A cross-compiling solution is to explicitly eta-expand the method `Foo.apply`.
152
-
153
152
~~~scala
154
153
caseclassFoo(x: Int, b: Boolean)
155
154
@@ -187,8 +186,8 @@ case class Location(lat: Double, long: Double)
187
186
{% endtab %}
188
187
{% endtabs %}
189
188
190
-
{% tabs unapply_2 class=tabs-scala-version %}
191
-
{% tab 'Scala 2' for=unapply_2 %}
189
+
{% tabs scala-2-unapply_2 %}
190
+
{% tab 'Scala 2 Only' %}
192
191
193
192
The Scala 2.13 compiler generates the following `unapply` method:
194
193
@@ -198,7 +197,10 @@ object Location {
198
197
}
199
198
~~~
200
199
{% endtab %}
201
-
{% tab 'Scala 3' for=unapply_2 %}
200
+
{% endtabs %}
201
+
202
+
{% tabs scala-3-unapply_2 %}
203
+
{% tab 'Scala 3 Only' %}
202
204
203
205
Whereas the Scala 3 compiler generates:
204
206
~~~scala
@@ -223,15 +225,15 @@ A possible solution is to use pattern binding:
223
225
224
226
~~~scala
225
227
deftuple(location: Location): (Int, Int) = {
226
-
Location.unapply(location).get
228
+
Location.unapply(location).get
227
229
}
228
230
~~~
229
231
{% endtab %}
230
232
{% tab 'Scala 3' for=unaply_3 %}
231
233
~~~scala
232
234
deftuple(location: Location): (Int, Int) = {
233
-
valLocation(lat, lon) = location
234
-
(lat, lon)
235
+
valLocation(lat, lon) = location
236
+
(lat, lon)
235
237
}
236
238
~~~
237
239
{% endtab %}
@@ -291,9 +293,8 @@ A type of the form `=> T` cannot be used as an argument to a type parameter anym
291
293
This decision is explained in [this comment](https://github.com/lampepfl/dotty/blob/0f1a23e008148f76fd0a1c2991b991e1dad600e8/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala#L144-L152) of the Scala 3 source code.
292
294
293
295
For instance, it is not allowed to pass a function of type `Int => (=> Int) => Int` to the `uncurried` method since it would assign `=> Int` to the type parameter `T2`.
294
-
{% tabs scala-3-type_1 %}
295
-
{% tab 'Scala 3 Only' %}
296
-
~~~scala
296
+
297
+
{% highlight text %}
297
298
-- [E134] Type Mismatch Error: src/main/scala/by-name-param-type-infer.scala:3:41
298
299
3 | val g: (Int, => Int) => Int = Function.uncurried(f)
299
300
| ^^^^^^^^^^^^^^^^^^
@@ -304,9 +305,7 @@ For instance, it is not allowed to pass a function of type `Int => (=> Int) => I
304
305
| [T1, T2, T3, R](f: T1 => T2 => T3 => R): (T1, T2, T3) => R
305
306
| [T1, T2, R](f: T1 => T2 => R): (T1, T2) => R
306
307
|match arguments ((Test.f : Int => (=> Int) => Int))
307
-
~~~
308
-
{% endtab %}
309
-
{% endtabs %}
308
+
{% endhighlight %}
310
309
311
310
The solution depends on the situation. In the given example, you can either:
312
311
- define your own `uncurried` method with the appropriate signature
0 commit comments