Skip to content

Commit 86e9a42

Browse files
authored
Merge pull request #11786 from rjolly/convert
Make `convert` available without import
2 parents a081a74 + ddd7449 commit 86e9a42

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

language-server/test/dotty/tools/languageserver/CompletionTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CompletionTest {
3030

3131
@Test def completionFromScalaPackage: Unit = {
3232
code"class Foo { val foo: Conv${m1} }".withSource
33-
.completion(m1, Set(("Conversion", Class, "class and object Conversion")))
33+
.completion(m1, Set(("Conversion", Class, "scala.Conversion")))
3434
}
3535

3636
@Test def completionFromScalaPackageObject: Unit = {

library/src/scala/Conversion.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ package scala
2525
abstract class Conversion[-T, +U] extends Function1[T, U]:
2626
/** Convert value `x` of type `T` to type `U` */
2727
def apply(x: T): U
28-
object Conversion:
2928

30-
extension [T](x: T)
31-
/** `x.convert[U]` converts a value `x` of type `T` to type `U` */
32-
def convert[U](using c: Conversion[T, U]) = c(x)
29+
extension (x: T)
30+
/** `x.convert` converts a value `x` of type `T` to type `U` */
31+
def convert = this(x)

tests/pos/convert.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import Conversion.convert
1+
import java.util.Date
22

33
given Conversion[String, Int] = _.length
44
given Conversion[Int, String] = _.toString
5+
given Conversion[Int, Date] = new Date(_)
56

67
def f(x: String): Int = x.convert
7-
def g(x: Int): String = x.convert[String]
8+
def g(x: Int): String = x.convert
9+
def h(x: Int): Date = x.convert

0 commit comments

Comments
 (0)