Skip to content

Commit e2a3498

Browse files
retronymadriaanm
authored andcommitted
Make parameters to implicit value classes private
So that they aren't offered as an autocomplete suggestion: implicit class Shouty(string: String) extends AnyVal { def SHOUT_! = string.toUpperCase + "!" } "". // autocompletion offers `.string` here The original incarnation of value classes didn't allow this sort of encapsulation, so we either invented goofy names like `__thingToAdd` or just picked `x` or `self`. But SI-7859 has delivered us the freedom to keep the accessor private. Should we keep any of these accessors around in a deprecated form? The implicit classes in Predef were added in 2.11.0-M2 (c26a8db), so they are okay. I think we can make reason that these APIs were both accidental and unlikely to be interpreted as public, so we can break them immediately. scala> Left(1).x res0: scala.util.Either[Int,Int] = Left(1) scala> import concurrent.duration._ import concurrent.duration._ scala> 1.n res1: Int = 1
1 parent beed168 commit e2a3498

File tree

13 files changed

+38
-98
lines changed

13 files changed

+38
-98
lines changed

src/compiler/scala/tools/nsc/util/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ package object util {
7575
s"$clazz$msg @ $frame"
7676
}
7777

78-
implicit class StackTraceOps(val e: Throwable) extends AnyVal with StackTracing {
78+
implicit class StackTraceOps(private val e: Throwable) extends AnyVal with StackTracing {
7979
/** Format the stack trace, returning the prefix consisting of frames that satisfy
8080
* a given predicate.
8181
* The format is similar to the typical case described in the JavaDoc

src/library/scala/Predef.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,33 +244,33 @@ object Predef extends LowPriorityImplicits with DeprecatedPredef {
244244

245245
// implicit classes -----------------------------------------------------
246246

247-
implicit final class ArrowAssoc[A](val __leftOfArrow: A) extends AnyVal {
248-
@inline def -> [B](y: B): Tuple2[A, B] = Tuple2(__leftOfArrow, y)
247+
implicit final class ArrowAssoc[A](private val self: A) extends AnyVal {
248+
@inline def -> [B](y: B): Tuple2[A, B] = Tuple2(self, y)
249249
def [B](y: B): Tuple2[A, B] = ->(y)
250250
}
251251

252-
implicit final class Ensuring[A](val __resultOfEnsuring: A) extends AnyVal {
253-
def ensuring(cond: Boolean): A = { assert(cond); __resultOfEnsuring }
254-
def ensuring(cond: Boolean, msg: => Any): A = { assert(cond, msg); __resultOfEnsuring }
255-
def ensuring(cond: A => Boolean): A = { assert(cond(__resultOfEnsuring)); __resultOfEnsuring }
256-
def ensuring(cond: A => Boolean, msg: => Any): A = { assert(cond(__resultOfEnsuring), msg); __resultOfEnsuring }
252+
implicit final class Ensuring[A](private val self: A) extends AnyVal {
253+
def ensuring(cond: Boolean): A = { assert(cond); self }
254+
def ensuring(cond: Boolean, msg: => Any): A = { assert(cond, msg); self }
255+
def ensuring(cond: A => Boolean): A = { assert(cond(self)); self }
256+
def ensuring(cond: A => Boolean, msg: => Any): A = { assert(cond(self), msg); self }
257257
}
258258

259-
implicit final class StringFormat[A](val __stringToFormat: A) extends AnyVal {
259+
implicit final class StringFormat[A](private val self: A) extends AnyVal {
260260
/** Returns string formatted according to given `format` string.
261261
* Format strings are as for `String.format`
262262
* (@see java.lang.String.format).
263263
*/
264-
@inline def formatted(fmtstr: String): String = fmtstr format __stringToFormat
264+
@inline def formatted(fmtstr: String): String = fmtstr format self
265265
}
266266

267-
implicit final class StringAdd[A](val __thingToAdd: A) extends AnyVal {
268-
def +(other: String) = String.valueOf(__thingToAdd) + other
267+
implicit final class StringAdd[A](private val self: A) extends AnyVal {
268+
def +(other: String) = String.valueOf(self) + other
269269
}
270270

271-
implicit final class RichException(val __throwableToEnrich: Throwable) extends AnyVal {
271+
implicit final class RichException(private val self: Throwable) extends AnyVal {
272272
import scala.compat.Platform.EOL
273-
@deprecated("Use Throwable#getStackTrace", "2.11.0") def getStackTraceString = __throwableToEnrich.getStackTrace().mkString("", EOL, EOL)
273+
@deprecated("Use Throwable#getStackTrace", "2.11.0") def getStackTraceString = self.getStackTrace().mkString("", EOL, EOL)
274274
}
275275

276276
implicit final class SeqCharSequence(val __sequenceOfChars: scala.collection.IndexedSeq[Char]) extends CharSequence {

src/library/scala/concurrent/duration/package.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ package object duration {
4040
implicit def pairLongToDuration(p: (Long, TimeUnit)): FiniteDuration = Duration(p._1, p._2)
4141
implicit def durationToPair(d: Duration): (Long, TimeUnit) = (d.length, d.unit)
4242

43-
implicit final class DurationInt(val n: Int) extends AnyVal with DurationConversions {
43+
implicit final class DurationInt(private val n: Int) extends AnyVal with DurationConversions {
4444
override protected def durationIn(unit: TimeUnit): FiniteDuration = Duration(n.toLong, unit)
4545
}
4646

47-
implicit final class DurationLong(val n: Long) extends AnyVal with DurationConversions {
47+
implicit final class DurationLong(private val n: Long) extends AnyVal with DurationConversions {
4848
override protected def durationIn(unit: TimeUnit): FiniteDuration = Duration(n, unit)
4949
}
5050

51-
implicit final class DurationDouble(val d: Double) extends AnyVal with DurationConversions {
51+
implicit final class DurationDouble(private val d: Double) extends AnyVal with DurationConversions {
5252
override protected def durationIn(unit: TimeUnit): FiniteDuration =
5353
Duration(d, unit) match {
5454
case f: FiniteDuration => f
@@ -59,17 +59,17 @@ package object duration {
5959
/*
6060
* Avoid reflection based invocation by using non-duck type
6161
*/
62-
implicit final class IntMult(val i: Int) extends AnyVal {
62+
implicit final class IntMult(private val i: Int) extends AnyVal {
6363
def *(d: Duration) = d * i.toDouble
6464
def *(d: FiniteDuration) = d * i.toLong
6565
}
6666

67-
implicit final class LongMult(val i: Long) extends AnyVal {
67+
implicit final class LongMult(private val i: Long) extends AnyVal {
6868
def *(d: Duration) = d * i.toDouble
6969
def *(d: FiniteDuration) = d * i.toLong
7070
}
7171

72-
implicit final class DoubleMult(val f: Double) extends AnyVal {
72+
implicit final class DoubleMult(private val f: Double) extends AnyVal {
7373
def *(d: Duration) = d * f.toDouble
7474
}
7575
}

src/library/scala/util/Either.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ object Either {
216216
* r.merge: Seq[Int] // Vector(1)
217217
* }}}
218218
*/
219-
implicit class MergeableEither[A](val x: Either[A, A]) extends AnyVal {
219+
implicit class MergeableEither[A](private val x: Either[A, A]) extends AnyVal {
220220
def merge: A = x match {
221221
case Left(a) => a
222222
case Right(a) => a

test/files/neg/logImplicits.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ logImplicits.scala:7: applied implicit conversion from String("abc") to ?{def ma
77
logImplicits.scala:15: inferred view from String("abc") to Int = C.this.convert:(p: String("abc"))Int
88
math.max(122, x: Int)
99
^
10-
logImplicits.scala:19: applied implicit conversion from Int(1) to ?{def ->: ?} = implicit def ArrowAssoc[A](__leftOfArrow: A): ArrowAssoc[A]
10+
logImplicits.scala:19: applied implicit conversion from Int(1) to ?{def ->: ?} = implicit def ArrowAssoc[A](self: A): ArrowAssoc[A]
1111
def f = (1 -> 2) + "c"
1212
^
13-
logImplicits.scala:19: applied implicit conversion from (Int, Int) to ?{def +: ?} = implicit def StringAdd[A](__thingToAdd: A): StringAdd[A]
13+
logImplicits.scala:19: applied implicit conversion from (Int, Int) to ?{def +: ?} = implicit def StringAdd[A](self: A): StringAdd[A]
1414
def f = (1 -> 2) + "c"
1515
^
1616
logImplicits.scala:22: error: class Un needs to be abstract, since method unimplemented is not defined

test/files/presentation/callcc-interpreter.check

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ reload: CallccInterpreter.scala
33
askTypeCompletion at CallccInterpreter.scala(51,38)
44
================================================================================
55
[response] askCompletionAt (51,38)
6-
retrieved 63 members
6+
retrieved 59 members
77
abstract trait Term extends AnyRef
88
abstract trait Value extends AnyRef
99
case class Add extends callccInterpreter.Term with Product with Serializable
@@ -52,10 +52,6 @@ final def synchronized[T0](x$1: T0): T0
5252
final def wait(): Unit
5353
final def wait(x$1: Long): Unit
5454
final def wait(x$1: Long,x$2: Int): Unit
55-
private[this] val __leftOfArrow: callccInterpreter.type
56-
private[this] val __resultOfEnsuring: callccInterpreter.type
57-
private[this] val __stringToFormat: callccInterpreter.type
58-
private[this] val __thingToAdd: callccInterpreter.type
5955
private[this] val term0: callccInterpreter.App
6056
private[this] val term1: callccInterpreter.App
6157
private[this] val term2: callccInterpreter.Add

test/files/presentation/ide-bug-1000349.check

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ reload: CompletionOnEmptyArgMethod.scala
33
askTypeCompletion at CompletionOnEmptyArgMethod.scala(2,17)
44
================================================================================
55
[response] askCompletionAt (2,17)
6-
retrieved 36 members
6+
retrieved 32 members
77
def +(other: String): String
88
def ->[B](y: B): (Foo, B)
99
def ensuring(cond: Boolean): Foo
@@ -31,10 +31,6 @@ final def synchronized[T0](x$1: T0): T0
3131
final def wait(): Unit
3232
final def wait(x$1: Long): Unit
3333
final def wait(x$1: Long,x$2: Int): Unit
34-
private[this] val __leftOfArrow: Foo
35-
private[this] val __resultOfEnsuring: Foo
36-
private[this] val __stringToFormat: Foo
37-
private[this] val __thingToAdd: Foo
3834
protected[package lang] def clone(): Object
3935
protected[package lang] def finalize(): Unit
4036
================================================================================

test/files/presentation/ide-bug-1000475.check

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ reload: Foo.scala
33
askTypeCompletion at Foo.scala(3,7)
44
================================================================================
55
[response] askCompletionAt (3,7)
6-
retrieved 35 members
6+
retrieved 31 members
77
[inaccessible] protected[package lang] def clone(): Object
88
[inaccessible] protected[package lang] def finalize(): Unit
99
def +(other: String): String
@@ -32,16 +32,12 @@ final def synchronized[T0](x$1: T0): T0
3232
final def wait(): Unit
3333
final def wait(x$1: Long): Unit
3434
final def wait(x$1: Long,x$2: Int): Unit
35-
private[this] val __leftOfArrow: Object
36-
private[this] val __resultOfEnsuring: Object
37-
private[this] val __stringToFormat: Object
38-
private[this] val __thingToAdd: Object
3935
================================================================================
4036

4137
askTypeCompletion at Foo.scala(6,10)
4238
================================================================================
4339
[response] askCompletionAt (6,10)
44-
retrieved 35 members
40+
retrieved 31 members
4541
[inaccessible] protected[package lang] def clone(): Object
4642
[inaccessible] protected[package lang] def finalize(): Unit
4743
def +(other: String): String
@@ -70,16 +66,12 @@ final def synchronized[T0](x$1: T0): T0
7066
final def wait(): Unit
7167
final def wait(x$1: Long): Unit
7268
final def wait(x$1: Long,x$2: Int): Unit
73-
private[this] val __leftOfArrow: Object
74-
private[this] val __resultOfEnsuring: Object
75-
private[this] val __stringToFormat: Object
76-
private[this] val __thingToAdd: Object
7769
================================================================================
7870

7971
askTypeCompletion at Foo.scala(7,7)
8072
================================================================================
8173
[response] askCompletionAt (7,7)
82-
retrieved 35 members
74+
retrieved 31 members
8375
[inaccessible] protected[package lang] def clone(): Object
8476
[inaccessible] protected[package lang] def finalize(): Unit
8577
def +(other: String): String
@@ -108,8 +100,4 @@ final def synchronized[T0](x$1: T0): T0
108100
final def wait(): Unit
109101
final def wait(x$1: Long): Unit
110102
final def wait(x$1: Long,x$2: Int): Unit
111-
private[this] val __leftOfArrow: Object
112-
private[this] val __resultOfEnsuring: Object
113-
private[this] val __stringToFormat: Object
114-
private[this] val __thingToAdd: Object
115103
================================================================================

test/files/presentation/ide-bug-1000531.check

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ reload: CrashOnLoad.scala
33
askTypeCompletion at CrashOnLoad.scala(6,12)
44
================================================================================
55
[response] askCompletionAt (6,12)
6-
retrieved 124 members
6+
retrieved 120 members
77
[inaccessible] protected[package lang] def clone(): Object
88
[inaccessible] protected[package lang] def finalize(): Unit
99
[inaccessible] protected[this] def reversed: List[B]
@@ -121,8 +121,4 @@ final def synchronized[T0](x$1: T0): T0
121121
final def wait(): Unit
122122
final def wait(x$1: Long): Unit
123123
final def wait(x$1: Long,x$2: Int): Unit
124-
private[this] val __leftOfArrow: java.util.Iterator[B]
125-
private[this] val __resultOfEnsuring: java.util.Iterator[B]
126-
private[this] val __stringToFormat: java.util.Iterator[B]
127-
private[this] val __thingToAdd: java.util.Iterator[B]
128124
================================================================================

test/files/presentation/implicit-member.check

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ reload: ImplicitMember.scala
33
askTypeCompletion at ImplicitMember.scala(7,7)
44
================================================================================
55
[response] askCompletionAt (7,7)
6-
retrieved 38 members
6+
retrieved 34 members
77
def +(other: String): String
88
def ->[B](y: B): (Implicit.type, B)
99
def ensuring(cond: Boolean): Implicit.type
@@ -32,10 +32,6 @@ final def wait(): Unit
3232
final def wait(x$1: Long): Unit
3333
final def wait(x$1: Long,x$2: Int): Unit
3434
implicit def AppliedImplicit[A](x: A): Implicit.AppliedImplicit[A]
35-
private[this] val __leftOfArrow: Implicit.type
36-
private[this] val __resultOfEnsuring: Implicit.type
37-
private[this] val __stringToFormat: Implicit.type
38-
private[this] val __thingToAdd: Implicit.type
3935
private[this] val x: Implicit.type
4036
protected[package lang] def clone(): Object
4137
protected[package lang] def finalize(): Unit

0 commit comments

Comments
 (0)