-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt apply/tupled/curried insertion for case companion
- Loading branch information
Showing
9 changed files
with
107 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
t3664b.scala:9: warning: The method `apply` is inserted. The auto insertion will be deprecated, please write `C.apply` explicitly. | ||
def f(xs: List[Int]): List[C] = xs.map(C) | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
1 warning | ||
1 error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//> using options -Werror -Xlint -Xsource:3-cross | ||
|
||
// use -Xsource:3 to warn that implicitly extending Function is deprecated | ||
// use -Xsource:3-cross for dotty behavior: no extend Function, yes adapt C.apply.tupled | ||
|
||
case class C(i: Int) | ||
|
||
class Test { | ||
def f(xs: List[Int]): List[C] = xs.map(C) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
//> using options -Werror -Xlint -Xsource:3-cross | ||
|
||
import language.implicitConversions | ||
|
||
case class C(i: Int) | ||
object C // no function parent | ||
|
||
// use conversion, don't warn about apply insertion | ||
class Test { | ||
implicit def cv(c: C.type): Function[Int, C] = C(_) | ||
def f(xs: List[Int]): List[C] = xs.map(C) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
t3664.scala:10: warning: The method `apply` is inserted. The auto insertion will be deprecated, please write `B.apply` explicitly. | ||
def mapped(xs: List[Int]): List[B] = xs.map(B) | ||
^ | ||
t3664.scala:15: warning: The method `apply` is inserted. The auto insertion will be deprecated, please write `(C.apply _).tupled` explicitly. | ||
def f(xs: List[(Int, Int)]): List[C] = xs.map(C.tupled) | ||
^ | ||
t3664.scala:17: warning: The method `apply` is inserted. The auto insertion will be deprecated, please write `(C.apply _).curried` explicitly. | ||
def g(xs: List[Int]): List[C] = xs.map(C.curried).map(_(42)) | ||
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//> using options -Xlint -Xsource:3-cross | ||
|
||
// use -Xsource:3 to warn that implicitly extending Function is deprecated | ||
// use -Xsource:3-cross for dotty behavior: no extend Function, yes adapt C.apply.tupled | ||
|
||
case class B(i: Int) | ||
case class C(i: Int, j: Int) | ||
|
||
class Test { | ||
def mapped(xs: List[Int]): List[B] = xs.map(B) | ||
|
||
// accept for cross because dotty has no C.tupled but has fancy untupling adaptation | ||
//def cross(xs: List[(Int, Int)]): List[C] = xs.map(C) | ||
|
||
def f(xs: List[(Int, Int)]): List[C] = xs.map(C.tupled) | ||
|
||
def g(xs: List[Int]): List[C] = xs.map(C.curried).map(_(42)) | ||
|
||
def f2(xs: List[(Int, Int)]): List[C] = xs.map((C.apply _).tupled) | ||
|
||
def g2(xs: List[Int]): List[C] = xs.map((C.apply _).curried).map(_(42)) | ||
|
||
def g3(xs: List[Int]): List[C] = xs.map(((i: Int, j: Int) => C.apply(i, j)).curried).map(_(42)) | ||
} | ||
object Test extends Test with App { | ||
assert(mapped(List(52)) == List(B(52))) | ||
//assert(cross(List(27->42)) == List(C(27, 42))) | ||
assert(f(List(27->42)) == List(C(27, 42))) | ||
assert(g(List(27)) == List(C(27, 42))) | ||
} |