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
Implement into modifier on parameter types (#14514)
in the thread
https://contributors.scala-lang.org/t/proposed-changes-and-restrictions-for-implicit-conversions/4923
we discussed two changes that would make implicit conversions largely
redundant. One proposed change was implemented in #14497. The other is
implemented here. It's based on #14497.
The idea of this PR is to have some way to specify that a method
parameter accepts implicit conversions on its arguments. Then the
feature warning on implicit conversion use would be suppressed in this
case. In the previous thread I proposed
`~` to mark convertible arguments but I now feel this is too cryptic.
Instead there is a `into` prefix in the
parameter type. E.g.
```scala
def f(x: into T) = ...
```
For Scala 2, we introduce an annotation on the parameter that expresses
the same thing:
```scala
// proposed Scala-2 syntax:
def f(@allowConversions x: T) =
```
A larger example:
```scala
given Conversion[String, Text] = Text(_)
@main def Test =
def f(x: into Text, y: => into Text, zs: into Text*) =
println(s"${x.str} ${y.str} ${zs.map(_.str).mkString(" ")}")
f("abc", "def") // ok, no feature warning
f("abc", "def", "xyz", "uvw") // also ok
f("abc", "def", "xyz", Text("uvw")) // also ok
```
A larger example is a parser combinator library that works without
unrestricted implicit conversions:
[tests/run/Parser.scala](https://github.com/lampepfl/dotty/blob/0f113da1bacc01603740cde4a5bafbfae39895f0/tests/run/Parser.scala)
0 commit comments