Skip to content

Commit 69e9222

Browse files
committed
Make -> sugar an inline method
Must wait for 3.10.0 currently it is transparent inline, to avoid inline proxy objects appearing in capture sets and breaking type checking.
1 parent ba45875 commit 69e9222

File tree

7 files changed

+15
-9
lines changed

7 files changed

+15
-9
lines changed

library/src/scala/Predef.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ object Predef extends LowPriorityImplicits {
389389
// implicit classes -----------------------------------------------------
390390

391391
/** @group implicit-classes-any */
392+
@deprecated("Use `->` extension method instead.", since = "3.10.0")
392393
implicit final class ArrowAssoc[A](private val self: A) extends AnyVal {
394+
@deprecated("Use `->` extension method instead.", since = "3.10.0")
393395
@inline def -> [B](y: B): (A, B) = (self, y)
394396
@deprecated("Use `->` instead. If you still wish to display it as one character, consider using a font with programming ligatures such as Fira Code.", "2.13.0")
395397
def [B](y: B): (A, B) = ->(y)
@@ -609,6 +611,11 @@ object Predef extends LowPriorityImplicits {
609611
*/
610612
inline def runtimeChecked: x.type @RuntimeChecked = x: @RuntimeChecked
611613

614+
// extension method sugar ---------------------------------------------
615+
extension[A] (self: A)
616+
transparent inline def -> [B](y: B): (A, B) = (self, y)
617+
618+
612619
}
613620

614621
/** The `LowPriorityImplicits` class provides implicit values that

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionExtensionSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
453453
"""|baz(): Unit
454454
|copy(): Bar
455455
|qux: Unit
456+
|->[B](y: B): (Bar, B)
456457
|asInstanceOf[X0]: X0
457458
|canEqual(that: Any): Boolean
458459
|equals(x$0: Any): Boolean
@@ -467,7 +468,6 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
467468
|productPrefix: String
468469
|synchronized[X0](x$0: X0): X0
469470
|toString(): String
470-
|->[B](y: B): (Bar, B)
471471
|ensuring(cond: Boolean): Bar
472472
|ensuring(cond: Bar => Boolean): Bar
473473
|ensuring(cond: Boolean, msg: => Any): Bar

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class CompletionSuite extends BaseCompletionSuite:
109109
|tabulate[A](n: Int)(f: Int => A): List[A]
110110
|unapplySeq[A](x: List[A] @uncheckedVariance): UnapplySeqWrapper[A]
111111
|unfold[A, S](init: S)(f: S => Option[(A, S)]): List[A]
112+
|->[B](y: B): (List.type, B)
112113
|fromSpecific(from: Any)(it: IterableOnce[Nothing]): List[Nothing]
113114
|fromSpecific(it: IterableOnce[Nothing]): List[Nothing]
114115
|toFactory(from: Any): Factory[Nothing, List[Nothing]]
@@ -120,7 +121,6 @@ class CompletionSuite extends BaseCompletionSuite:
120121
|isInstanceOf[X0]: Boolean
121122
|synchronized[X0](x$0: X0): X0
122123
|toString(): String
123-
|->[B](y: B): (List.type, B)
124124
|ensuring(cond: Boolean): List.type
125125
|ensuring(cond: List.type => Boolean): List.type
126126
|ensuring(cond: Boolean, msg: => Any): List.type

tests/run-staging/i5965.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ List(1, 2, 3)
1111
}
1212
Some(4)
1313
{
14-
val y: [V >: scala.Nothing <: scala.Any] =>> scala.collection.immutable.Map[scala.Int, V][scala.Int] = scala.Predef.Map.apply[scala.Int, scala.Int](scala.Predef.ArrowAssoc[scala.Int](4).->[scala.Int](1))
14+
val y: [V >: scala.Nothing <: scala.Any] =>> scala.collection.immutable.Map[scala.Int, V][scala.Int] = scala.Predef.Map.apply[scala.Int, scala.Int](scala.Predef.->[scala.Int](4)[scala.Int](1))
1515

1616
(y: scala.collection.immutable.Map[scala.Int, scala.Int])
1717
}

tests/run-staging/i5965b.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ List(1, 2, 3)
1111
}
1212
Some(4)
1313
{
14-
val y: scala.collection.immutable.Map[scala.Int, scala.Int] = scala.Predef.Map.apply[scala.Int, scala.Int](scala.Predef.ArrowAssoc[scala.Int](4).->[scala.Int](1))
14+
val y: scala.collection.immutable.Map[scala.Int, scala.Int] = scala.Predef.Map.apply[scala.Int, scala.Int](scala.Predef.->[scala.Int](4)[scala.Int](1))
1515

1616
(y: scala.collection.immutable.Map[scala.Int, scala.Int])
1717
}

tests/semanticdb/expect/Synthetic.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Synthetic/*<-example::Synthetic#*/ {
1717

1818
val lst/*<-example::Synthetic#lst.*/ = 1 #:: 2 #:: LazyList/*->scala::package.LazyList.*/.empty/*->scala::collection::immutable::LazyList.empty().*/
1919

20-
for (x/*<-local0*/ <- 1 to/*->scala::runtime::RichInt#to().*/ 10; y/*<-local1*/ <- 0 until/*->scala::runtime::RichInt#until().*/ 10) println/*->scala::Predef.println(+1).*/(x/*->local0*/ ->/*->scala::Predef.ArrowAssoc#`->`().*/ x/*->local0*/)
20+
for (x/*<-local0*/ <- 1 to/*->scala::runtime::RichInt#to().*/ 10; y/*<-local1*/ <- 0 until/*->scala::runtime::RichInt#until().*/ 10) println/*->scala::Predef.println(+1).*/(x/*->local0*/ ->/*->scala::Predef.`->`().*/ x/*->local0*/)
2121
for (i/*<-local2*/ <- 1 to/*->scala::runtime::RichInt#to().*/ 10; j/*<-local3*/ <- 0 until/*->scala::runtime::RichInt#until().*/ 10) yield (i/*->local2*/, j/*->local3*/)
2222
for (i/*<-local4*/ <- 1 to/*->scala::runtime::RichInt#to().*/ 10; j/*<-local5*/ <- 0 until/*->scala::runtime::RichInt#until().*/ 10 if i/*->local4*/ %/*->scala::Int#`%`(+3).*/ 2 ==/*->scala::Int#`==`(+3).*/ 0) yield (i/*->local4*/, j/*->local5*/)
2323

tests/semanticdb/metac.expect

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3838,7 +3838,7 @@ Language => Scala
38383838
Symbols => 62 entries
38393839
Occurrences => 165 entries
38403840
Diagnostics => 4 entries
3841-
Synthetics => 48 entries
3841+
Synthetics => 47 entries
38423842

38433843
Symbols:
38443844
example/Synthetic# => class Synthetic extends Object { self: Synthetic => +23 decls }
@@ -3944,7 +3944,7 @@ Occurrences:
39443944
[19:28..19:33): until -> scala/runtime/RichInt#until().
39453945
[19:38..19:45): println -> scala/Predef.println(+1).
39463946
[19:46..19:47): x -> local0
3947-
[19:48..19:50): -> -> scala/Predef.ArrowAssoc#`->`().
3947+
[19:48..19:50): -> -> scala/Predef.`->`().
39483948
[19:51..19:52): x -> local0
39493949
[20:7..20:8): i <- local2
39503950
[20:14..20:16): to -> scala/runtime/RichInt#to().
@@ -4104,8 +4104,7 @@ Synthetics:
41044104
[17:24..17:38):LazyList.empty => *[Nothing]
41054105
[19:12..19:13):1 => intWrapper(*)
41064106
[19:26..19:27):0 => intWrapper(*)
4107-
[19:46..19:50):x -> => *[Int]
4108-
[19:46..19:47):x => ArrowAssoc[Int](*)
4107+
[19:48..19:50):-> => *[Int]
41094108
[20:12..20:13):1 => intWrapper(*)
41104109
[20:26..20:27):0 => intWrapper(*)
41114110
[20:44..20:50):(i, j) => Tuple2.apply[Int, Int](*)

0 commit comments

Comments
 (0)