Skip to content

Commit 176b118

Browse files
committed
Add test
1 parent 408d9f3 commit 176b118

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

docs/_docs/reference/experimental/into.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ Example:
145145
into class Keyword
146146
given stringToKeyword: Conversion[String, Keyword] = Keyword(_)
147147

148-
val dclKeywords = List("def", "val")
149-
val xs: List[Keyword] = dclkeywords ++ List("if", "then", "else")
148+
val dclKeywords = Set[Keyword]("def", "val") // ok
149+
val keywords = dclKeywords + "if" + "then" + "else" // ok
150150
```
151-
Here, the strings `"if"`, `"then"`, and `"else"` are converted to `Keyword` using the given conversion `stringToKeyword`. No feature warning or error is issued since `Keyword` is declared as `into`.
151+
Here, all string literals are converted to `Keyword` using the given conversion `stringToKeyword`. No feature warning or error is issued since `Keyword` is declared as `into`.
152152

153153
The `into`-as-a-modifier scheme is handy in codebases that have a small set of specific types that are intended to be the targets of implicit conversions defined in the same codebase. But it can be easily abused.
154154
One should restrict the number of `into`-declared types to the absolute minimum. In particular, never make a type `into` to just cater for the

tests/pos/into-expr.scala

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
//> using options -feature -Xfatal-warnings
3+
4+
import language.experimental.into
5+
import Conversion.into
6+
7+
enum Expr:
8+
case Neg(e: into[Expr])
9+
case Add(e1: into[Expr], e2: into[Expr])
10+
case Const(n: Int)
11+
import Expr.*
12+
13+
given Conversion[Int, Const] = Const(_)
14+
15+
def Test =
16+
Add(1, Neg(2))

0 commit comments

Comments
 (0)