Skip to content

Commit b7cb5de

Browse files
committed
Address review comments; avoid inferred flexible types
1 parent 01a8a85 commit b7cb5de

File tree

17 files changed

+101
-98
lines changed

17 files changed

+101
-98
lines changed

library/src/scala/MatchError.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class MatchError(@transient obj: Any) extends RuntimeException {
2222
/** There's no reason we need to call toString eagerly,
2323
* so defer it until getMessage is called or object is serialized
2424
*/
25-
private[this] lazy val objString = {
25+
private[this] lazy val objString: String = {
2626
def ofClass = "of class " + obj.getClass.getName
2727
if (obj == null) "null"
2828
else
@@ -38,5 +38,5 @@ final class MatchError(@transient obj: Any) extends RuntimeException {
3838
this
3939
}
4040

41-
override def getMessage() = objString
41+
override def getMessage(): String = objString
4242
}

library/src/scala/collection/SeqView.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ object SeqView {
138138
extends SeqView[A] {
139139
outer: Sorted[A, B]^ =>
140140

141-
private var underlying: SomeSeqOps[A]^{underlying_} | Null = underlying_
141+
private var underlying = underlying_
142142

143143
// force evaluation immediately by calling `length` so infinite collections
144144
// hang on `sorted`/`sortWith`/`sortBy` rather than on arbitrary method calls
@@ -169,10 +169,10 @@ object SeqView {
169169
val res = {
170170
val len = this.len
171171
if (len == 0) Nil
172-
else if (len == 1) List(underlying.nn.head)
172+
else if (len == 1) List(underlying.head)
173173
else {
174174
val arr = new Array[Any](len) // Array[Any] =:= Array[AnyRef]
175-
@annotation.unused val copied = underlying.nn.copyToArray(arr)
175+
@annotation.unused val copied = underlying.copyToArray(arr)
176176
//assert(copied == len)
177177
java.util.Arrays.sort(arr.asInstanceOf[Array[AnyRef]], ord.asInstanceOf[Ordering[AnyRef]])
178178
// casting the Array[AnyRef] to Array[A] and creating an ArraySeq from it
@@ -187,12 +187,12 @@ object SeqView {
187187
}
188188
}
189189
evaluated = true
190-
underlying = null
190+
underlying = nullForGC[SomeSeqOps[A]] // allow GC of unneeded reference
191191
res
192192
}
193193

194194
private[this] def elems: SomeSeqOps[A]^{this} = {
195-
if (evaluated) _sorted else underlying.nn
195+
if (evaluated) _sorted else underlying
196196
}
197197

198198
def apply(i: Int): A = _sorted.apply(i)

library/src/scala/collection/StringOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,14 +731,14 @@ final class StringOps(private val s: String) extends AnyVal { self =>
731731
/** Returns this string with the given `prefix` stripped. If this string does not
732732
* start with `prefix`, it is returned unchanged.
733733
*/
734-
def stripPrefix(prefix: String) =
734+
def stripPrefix(prefix: String): String =
735735
if (s startsWith prefix) s.substring(prefix.length)
736736
else s
737737

738738
/** Returns this string with the given `suffix` stripped. If this string does not
739739
* end with `suffix`, it is returned unchanged.
740740
*/
741-
def stripSuffix(suffix: String) =
741+
def stripSuffix(suffix: String): String =
742742
if (s endsWith suffix) s.substring(0, s.length - suffix.length)
743743
else s
744744

library/src/scala/collection/concurrent/TrieMap.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ private[collection] final class INode[K, V](bn: MainNode[K, V] | Null, g: Gen, e
410410
GCAS_READ(ct).nn.knownSize()
411411

412412
/* this is a quiescent method! */
413-
def string(lev: Int) = "%sINode -> %s".format(" " * lev, mainnode match {
413+
def string(lev: Int): String = "%sINode -> %s".format(" " * lev, mainnode match {
414414
case null => "<null>"
415415
case tn: TNode[_, _] => "TNode(%s, %s, %d, !)".format(tn.k, tn.v, tn.hc)
416416
case cn: CNode[_, _] => cn.string(lev)
@@ -446,7 +446,7 @@ private[concurrent] final class FailedNode[K, V](p: MainNode[K, V]) extends Main
446446

447447
def knownSize: Int = throw new UnsupportedOperationException
448448

449-
override def toString = "FailedNode(%s)".format(p)
449+
override def toString: String = "FailedNode(%s)".format(p)
450450
}
451451

452452

@@ -461,7 +461,7 @@ private[collection] final class SNode[K, V](final val k: K, final val v: V, fina
461461
def copyTombed = new TNode(k, v, hc)
462462
def copyUntombed = new SNode(k, v, hc)
463463
def kvPair = (k, v)
464-
def string(lev: Int) = (" " * lev) + "SNode(%s, %s, %x)".format(k, v, hc)
464+
def string(lev: Int): String = (" " * lev) + "SNode(%s, %s, %x)".format(k, v, hc)
465465
}
466466

467467
// Tomb Node, used to ensure proper ordering during removals
@@ -473,7 +473,7 @@ private[collection] final class TNode[K, V](final val k: K, final val v: V, fina
473473
def kvPair = (k, v)
474474
def cachedSize(ct: AnyRef): Int = 1
475475
def knownSize: Int = 1
476-
def string(lev: Int) = (" " * lev) + "TNode(%s, %s, %x, !)".format(k, v, hc)
476+
def string(lev: Int): String = (" " * lev) + "TNode(%s, %s, %x, !)".format(k, v, hc)
477477
}
478478

479479
// List Node, leaf node that handles hash collisions
@@ -514,7 +514,7 @@ private[collection] final class LNode[K, V](val entries: List[(K, V)], equiv: Eq
514514

515515
def knownSize: Int = -1 // shouldn't ever be empty, and the size of a list is not known
516516

517-
def string(lev: Int) = (" " * lev) + "LNode(%s)".format(entries.mkString(", "))
517+
def string(lev: Int): String = (" " * lev) + "LNode(%s)".format(entries.mkString(", "))
518518

519519
}
520520

@@ -839,7 +839,7 @@ final class TrieMap[K, V] private (r: AnyRef, rtupd: AtomicReferenceFieldUpdater
839839
}
840840

841841

842-
def string = RDCSS_READ_ROOT().string(0)
842+
def string: String = RDCSS_READ_ROOT().string(0)
843843

844844
/* public methods */
845845

@@ -1082,17 +1082,17 @@ private[collection] class TrieMapIterator[K, V](var level: Int, private var ct:
10821082

10831083
def hasNext = (current ne null) || (subiter ne null)
10841084

1085-
def next() = if (hasNext) {
1086-
var r: (K, V) | Null = null
1085+
def next(): (K, V) = {
10871086
if (subiter ne null) {
1088-
r = subiter.next()
1087+
val r = subiter.next()
10891088
checkSubiter()
1090-
} else {
1091-
r = current.nn.kvPair
1089+
r
1090+
} else if (current ne null) {
1091+
val r = current.kvPair
10921092
advance()
1093-
}
1094-
r
1095-
} else Iterator.empty.next()
1093+
r
1094+
} else Iterator.empty.next()
1095+
}
10961096

10971097
private def readin(in: INode[K, V]) = in.gcasRead(ct) match {
10981098
case cn: CNode[K, V] =>

library/src/scala/collection/convert/AsJavaConverters.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ trait AsJavaConverters {
4545
* @param i The Scala `Iterator` to be converted.
4646
* @return A Java `Iterator` view of the argument.
4747
*/
48-
def asJava[A](i: Iterator[A]): ju.Iterator[A] = i match {
48+
def asJava[A](i: Iterator[A]): ju.Iterator[A] = (i: Iterator[A] | Null) match {
4949
case null => null.asInstanceOf[ju.Iterator[A]]
5050
case wrapper: JIteratorWrapper[A @uc] => wrapper.underlying
5151
case _ => new IteratorWrapper(i)
@@ -63,7 +63,7 @@ trait AsJavaConverters {
6363
* @param i The Scala `Iterator` to be converted.
6464
* @return A Java `Enumeration` view of the argument.
6565
*/
66-
def asJavaEnumeration[A](i: Iterator[A]): ju.Enumeration[A] = i match {
66+
def asJavaEnumeration[A](i: Iterator[A]): ju.Enumeration[A] = (i: Iterator[A] | Null) match {
6767
case null => null.asInstanceOf[ju.Enumeration[A]]
6868
case wrapper: JEnumerationWrapper[A @uc] => wrapper.underlying
6969
case _ => new IteratorWrapper(i)
@@ -81,7 +81,7 @@ trait AsJavaConverters {
8181
* @param i The Scala `Iterable` to be converted.
8282
* @return A Java `Iterable` view of the argument.
8383
*/
84-
def asJava[A](i: Iterable[A]): jl.Iterable[A] = i match {
84+
def asJava[A](i: Iterable[A]): jl.Iterable[A] = (i: Iterable[A] | Null) match {
8585
case null => null.asInstanceOf[jl.Iterable[A]]
8686
case wrapper: JIterableWrapper[A @uc] => wrapper.underlying
8787
case _ => new IterableWrapper(i)
@@ -96,7 +96,7 @@ trait AsJavaConverters {
9696
* @param i The Scala `Iterable` to be converted.
9797
* @return A Java `Collection` view of the argument.
9898
*/
99-
def asJavaCollection[A](i: Iterable[A]): ju.Collection[A] = i match {
99+
def asJavaCollection[A](i: Iterable[A]): ju.Collection[A] = (i: Iterable[A] | Null) match {
100100
case null => null.asInstanceOf[ju.Collection[A]]
101101
case wrapper: JCollectionWrapper[A @uc] => wrapper.underlying
102102
case _ => new IterableWrapper(i)
@@ -114,7 +114,7 @@ trait AsJavaConverters {
114114
* @param b The Scala `Buffer` to be converted.
115115
* @return A Java `List` view of the argument.
116116
*/
117-
def asJava[A](b: mutable.Buffer[A]): ju.List[A] = b match {
117+
def asJava[A](b: mutable.Buffer[A]): ju.List[A] = (b: mutable.Buffer[A] | Null) match {
118118
case null => null.asInstanceOf[ju.List[A]]
119119
case wrapper: JListWrapper[A @uc] => wrapper.underlying
120120
case _ => new MutableBufferWrapper(b)
@@ -132,7 +132,7 @@ trait AsJavaConverters {
132132
* @param s The Scala `Seq` to be converted.
133133
* @return A Java `List` view of the argument.
134134
*/
135-
def asJava[A](s: mutable.Seq[A]): ju.List[A] = s match {
135+
def asJava[A](s: mutable.Seq[A]): ju.List[A] = (s: mutable.Seq[A] | Null) match {
136136
case null => null.asInstanceOf[ju.List[A]]
137137
case wrapper: JListWrapper[A @uc] => wrapper.underlying
138138
case _ => new MutableSeqWrapper(s)
@@ -150,7 +150,7 @@ trait AsJavaConverters {
150150
* @param s The Scala `Seq` to be converted.
151151
* @return A Java `List` view of the argument.
152152
*/
153-
def asJava[A](s: Seq[A]): ju.List[A] = s match {
153+
def asJava[A](s: Seq[A]): ju.List[A] = (s: Seq[A] | Null) match {
154154
case null => null.asInstanceOf[ju.List[A]]
155155
case wrapper: JListWrapper[A @uc] => wrapper.underlying
156156
case _ => new SeqWrapper(s)
@@ -168,7 +168,7 @@ trait AsJavaConverters {
168168
* @param s The Scala mutable `Set` to be converted.
169169
* @return A Java `Set` view of the argument.
170170
*/
171-
def asJava[A](s: mutable.Set[A]): ju.Set[A] = s match {
171+
def asJava[A](s: mutable.Set[A]): ju.Set[A] = (s: mutable.Set[A] | Null) match {
172172
case null => null.asInstanceOf[ju.Set[A]]
173173
case wrapper: JSetWrapper[A @uc] => wrapper.underlying
174174
case _ => new MutableSetWrapper(s)
@@ -186,7 +186,7 @@ trait AsJavaConverters {
186186
* @param s The Scala `Set` to be converted.
187187
* @return A Java `Set` view of the argument.
188188
*/
189-
def asJava[A](s: Set[A]): ju.Set[A] = s match {
189+
def asJava[A](s: Set[A]): ju.Set[A] = (s: Set[A] | Null) match {
190190
case null => null.asInstanceOf[ju.Set[A]]
191191
case wrapper: JSetWrapper[A @uc] => wrapper.underlying
192192
case _ => new SetWrapper(s)
@@ -204,7 +204,7 @@ trait AsJavaConverters {
204204
* @param m The Scala mutable `Map` to be converted.
205205
* @return A Java `Map` view of the argument.
206206
*/
207-
def asJava[K, V](m: mutable.Map[K, V]): ju.Map[K, V] = m match {
207+
def asJava[K, V](m: mutable.Map[K, V]): ju.Map[K, V] = (m: mutable.Map[K, V] | Null) match {
208208
case null => null.asInstanceOf[ju.Map[K, V]]
209209
case wrapper: JMapWrapper[K @uc, V @uc] => wrapper.underlying
210210
case _ => new MutableMapWrapper(m)
@@ -223,7 +223,7 @@ trait AsJavaConverters {
223223
* @param m The Scala `Map` to be converted.
224224
* @return A Java `Dictionary` view of the argument.
225225
*/
226-
def asJavaDictionary[K, V](m: mutable.Map[K, V]): ju.Dictionary[K, V] = m match {
226+
def asJavaDictionary[K, V](m: mutable.Map[K, V]): ju.Dictionary[K, V] = (m: mutable.Map[K, V] | Null) match {
227227
case null => null.asInstanceOf[ju.Dictionary[K, V]]
228228
case wrapper: JDictionaryWrapper[K @uc, V @uc] => wrapper.underlying
229229
case _ => new DictionaryWrapper(m)
@@ -241,7 +241,7 @@ trait AsJavaConverters {
241241
* @param m The Scala `Map` to be converted.
242242
* @return A Java `Map` view of the argument.
243243
*/
244-
def asJava[K, V](m: Map[K, V]): ju.Map[K, V] = m match {
244+
def asJava[K, V](m: Map[K, V]): ju.Map[K, V] = (m: Map[K, V] | Null) match {
245245
case null => null.asInstanceOf[ju.Map[K, V]]
246246
case wrapper: JMapWrapper[K @uc, V @uc] => wrapper.underlying
247247
case _ => new MapWrapper(m)
@@ -260,7 +260,7 @@ trait AsJavaConverters {
260260
* @param m The Scala `concurrent.Map` to be converted.
261261
* @return A Java `ConcurrentMap` view of the argument.
262262
*/
263-
def asJava[K, V](m: concurrent.Map[K, V]): juc.ConcurrentMap[K, V] = m match {
263+
def asJava[K, V](m: concurrent.Map[K, V]): juc.ConcurrentMap[K, V] = (m: concurrent.Map[K, V] | Null) match {
264264
case null => null.asInstanceOf[juc.ConcurrentMap[K, V]]
265265
case wrapper: JConcurrentMapWrapper[K @uc, V @uc] => wrapper.underlying
266266
case _ => new ConcurrentMapWrapper(m)

library/src/scala/collection/convert/AsScalaConverters.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ trait AsScalaConverters {
4646
* @param i The Java `Iterator` to be converted.
4747
* @return A Scala `Iterator` view of the argument.
4848
*/
49-
def asScala[A](i: ju.Iterator[A]): Iterator[A] = i match {
49+
def asScala[A](i: ju.Iterator[A]): Iterator[A] = (i: ju.Iterator[A] | Null) match {
5050
case null => null.asInstanceOf[Iterator[A]]
5151
case wrapper: IteratorWrapper[A @uc] => wrapper.underlying.unsafeAssumePure // TODO: Remove when pattern matching recognizes this is safe
5252
case _ => new JIteratorWrapper(i)
@@ -64,7 +64,7 @@ trait AsScalaConverters {
6464
* @param e The Java `Enumeration` to be converted.
6565
* @return A Scala `Iterator` view of the argument.
6666
*/
67-
def asScala[A](e: ju.Enumeration[A]): Iterator[A] = e match {
67+
def asScala[A](e: ju.Enumeration[A]): Iterator[A] = (e: ju.Enumeration[A] | Null) match {
6868
case null => null.asInstanceOf[Iterator[A]]
6969
case wrapper: IteratorWrapper[A @uc] => wrapper.underlying.unsafeAssumePure // TODO: Remove when pattern matching recognizes this is safe
7070
case _ => new JEnumerationWrapper(e)
@@ -82,7 +82,7 @@ trait AsScalaConverters {
8282
* @param i The Java `Iterable` to be converted.
8383
* @return A Scala `Iterable` view of the argument.
8484
*/
85-
def asScala[A](i: jl.Iterable[A]): Iterable[A] = i match {
85+
def asScala[A](i: jl.Iterable[A]): Iterable[A] = (i: jl.Iterable[A] | Null) match {
8686
case null => null.asInstanceOf[Iterable[A]]
8787
case wrapper: IterableWrapper[A @uc] => wrapper.underlying.unsafeAssumePure // TODO: Remove when pattern matching recognizes this is safe
8888
case _ => new JIterableWrapper(i)
@@ -97,7 +97,7 @@ trait AsScalaConverters {
9797
* @param c The Java `Collection` to be converted.
9898
* @return A Scala `Iterable` view of the argument.
9999
*/
100-
def asScala[A](c: ju.Collection[A]): Iterable[A] = c match {
100+
def asScala[A](c: ju.Collection[A]): Iterable[A] = (c: ju.Collection[A] | Null) match {
101101
case null => null.asInstanceOf[Iterable[A]]
102102
case wrapper: IterableWrapper[A @uc] => wrapper.underlying.unsafeAssumePure // TODO: Remove when pattern matching recognizes this is safe
103103
case _ => new JCollectionWrapper(c)
@@ -115,7 +115,7 @@ trait AsScalaConverters {
115115
* @param l The Java `List` to be converted.
116116
* @return A Scala mutable `Buffer` view of the argument.
117117
*/
118-
def asScala[A](l: ju.List[A]): mutable.Buffer[A] = l match {
118+
def asScala[A](l: ju.List[A]): mutable.Buffer[A] = (l: ju.List[A] | Null) match {
119119
case null => null.asInstanceOf[mutable.Buffer[A]]
120120
case wrapper: MutableBufferWrapper[A @uc] => wrapper.underlying
121121
case _ => new JListWrapper(l)
@@ -133,7 +133,7 @@ trait AsScalaConverters {
133133
* @param s The Java `Set` to be converted.
134134
* @return A Scala mutable `Set` view of the argument.
135135
*/
136-
def asScala[A](s: ju.Set[A]): mutable.Set[A] = s match {
136+
def asScala[A](s: ju.Set[A]): mutable.Set[A] = (s: ju.Set[A] | Null) match {
137137
case null => null.asInstanceOf[mutable.Set[A]]
138138
case wrapper: MutableSetWrapper[A @uc] => wrapper.underlying
139139
case _ => new JSetWrapper(s)
@@ -156,7 +156,7 @@ trait AsScalaConverters {
156156
* @param m The Java `Map` to be converted.
157157
* @return A Scala mutable `Map` view of the argument.
158158
*/
159-
def asScala[K, V](m: ju.Map[K, V]): mutable.Map[K, V] = m match {
159+
def asScala[K, V](m: ju.Map[K, V]): mutable.Map[K, V] = (m: ju.Map[K, V] | Null) match {
160160
case null => null.asInstanceOf[mutable.Map[K, V]]
161161
case wrapper: MutableMapWrapper[K @uc, V @uc] => wrapper.underlying
162162
case _ => new JMapWrapper(m)
@@ -175,7 +175,7 @@ trait AsScalaConverters {
175175
* @param m The Java `ConcurrentMap` to be converted.
176176
* @return A Scala mutable `ConcurrentMap` view of the argument.
177177
*/
178-
def asScala[K, V](m: juc.ConcurrentMap[K, V]): concurrent.Map[K, V] = m match {
178+
def asScala[K, V](m: juc.ConcurrentMap[K, V]): concurrent.Map[K, V] = (m: juc.ConcurrentMap[K, V] | Null) match {
179179
case null => null.asInstanceOf[concurrent.Map[K, V]]
180180
case wrapper: ConcurrentMapWrapper[K @uc, V @uc] => wrapper.underlyingConcurrentMap
181181
case _ => new JConcurrentMapWrapper(m)
@@ -193,7 +193,7 @@ trait AsScalaConverters {
193193
* @param d The Java `Dictionary` to be converted.
194194
* @return A Scala mutable `Map` view of the argument.
195195
*/
196-
def asScala[K, V](d: ju.Dictionary[K, V]): mutable.Map[K, V] = d match {
196+
def asScala[K, V](d: ju.Dictionary[K, V]): mutable.Map[K, V] = (d: ju.Dictionary[K, V] | Null) match {
197197
case null => null.asInstanceOf[mutable.Map[K, V]]
198198
case wrapper: DictionaryWrapper[K @uc, V @uc] => wrapper.underlying
199199
case _ => new JDictionaryWrapper(d)
@@ -209,7 +209,7 @@ trait AsScalaConverters {
209209
* @param p The Java `Properties` to be converted.
210210
* @return A Scala mutable `Map[String, String]` view of the argument.
211211
*/
212-
def asScala(p: ju.Properties): mutable.Map[String, String] = p match {
212+
def asScala(p: ju.Properties): mutable.Map[String, String] = (p: ju.Properties | Null) match {
213213
case null => null.asInstanceOf[mutable.Map[String, String]]
214214
case _ => new JPropertiesWrapper(p)
215215
}

0 commit comments

Comments
 (0)