Skip to content

Commit

Permalink
Unit annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed May 26, 2022
1 parent fadde34 commit 28a7770
Show file tree
Hide file tree
Showing 80 changed files with 276 additions and 293 deletions.
2 changes: 1 addition & 1 deletion src/compiler/scala/reflect/quasiquotes/Placeholders.scala
Expand Up @@ -32,7 +32,7 @@ trait Placeholders { self: Quasiquotes =>
lazy val code = {
val sb = new StringBuilder()

def appendPart(value: String, pos: Position) = {
def appendPart(value: String, pos: Position): Unit = {
val start = sb.length
sb.append(value)
val end = sb.length
Expand Down
16 changes: 9 additions & 7 deletions src/compiler/scala/reflect/reify/Reifier.scala
Expand Up @@ -65,12 +65,14 @@ abstract class Reifier extends States
if (universe exists (_.isErroneous)) CannotReifyErroneousPrefix(universe)
if (universe.tpe == null) CannotReifyUntypedPrefix(universe)

def reifyTraceOut[A](msg: => String)(a: A) = reifyTrace(msg)(a): Unit

val result = reifee match {
case tree: Tree =>
reifyTrace("reifying = ")(if (settings.Xshowtrees || settings.XshowtreesCompact || settings.XshowtreesStringified) "\n" + nodePrinters.nodeToString(tree).trim else tree.toString)
reifyTrace("reifee is located at: ")(tree.pos)
reifyTrace("universe = ")(universe)
reifyTrace("mirror = ")(mirror)
reifyTraceOut("reifying = ")(if (settings.Xshowtrees || settings.XshowtreesCompact || settings.XshowtreesStringified) "\n" + nodePrinters.nodeToString(tree).trim else tree.toString)
reifyTraceOut("reifee is located at: ")(tree.pos)
reifyTraceOut("universe = ")(universe)
reifyTraceOut("mirror = ")(mirror)
if (tree exists (_.isErroneous)) CannotReifyErroneousReifee(tree)
if (tree.tpe == null) CannotReifyUntypedReifee(tree)
val pipeline = mkReificationPipeline
Expand All @@ -83,9 +85,9 @@ abstract class Reifier extends States
ReifiedTree(universe, mirror, symtab, rtree, tpe, rtpe, reificationIsConcrete)

case tpe: Type =>
reifyTrace("reifying = ")(tpe.toString)
reifyTrace("universe = ")(universe)
reifyTrace("mirror = ")(mirror)
reifyTraceOut("reifying = ")(tpe.toString)
reifyTraceOut("universe = ")(universe)
reifyTraceOut("mirror = ")(mirror)
val rtree = reify(tpe)
ReifiedType(universe, mirror, symtab, tpe, rtree, reificationIsConcrete)

Expand Down
6 changes: 3 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/Infer.scala
Expand Up @@ -84,12 +84,12 @@ trait Infer extends Checkable {
val ptVars = appliedType(samTyCon, tvars)

// carry over info from pt
ptVars <:< samTp
ptVars <:< samTp: Unit

val samInfoWithTVars = ptVars.memberInfo(sam)

// use function type subtyping, not method type subtyping (the latter is invariant in argument types)
funTp <:< functionType(samInfoWithTVars.paramTypes, samInfoWithTVars.finalResultType)
funTp <:< functionType(samInfoWithTVars.paramTypes, samInfoWithTVars.finalResultType): Unit

// solve constraints tracked by tvars
val targs = solvedTypes(tvars, tparams, varianceInType(sam.info), upper = false, lubDepth(sam.info :: Nil))
Expand Down Expand Up @@ -1401,7 +1401,7 @@ trait Infer extends Checkable {
}
// todo: missing test case for bests.isEmpty
bests match {
case best :: Nil => tree setSymbol best setType (pre memberType best)
case best :: Nil => tree.setSymbol(best).setType(pre.memberType(best))
case best :: competing :: _ if alts0.nonEmpty =>
// scala/bug#6912 Don't give up and leave an OverloadedType on the tree.
// Originally I wrote this as `if (secondTry) ... `, but `tryTwice` won't attempt the second try
Expand Down
12 changes: 6 additions & 6 deletions src/library/scala/MatchError.scala
Expand Up @@ -23,16 +23,16 @@ final class MatchError(@transient obj: Any) extends RuntimeException {
private[this] lazy val objString = {
def ofClass = "of class " + obj.getClass.getName
if (obj == null) "null"
else try {
obj.toString() + " (" + ofClass + ")"
} catch {
case _: Throwable => "an instance " + ofClass
}
else
try s"$obj ($ofClass)"
catch {
case _: Throwable => "an instance " + ofClass
}
}

@throws[java.io.ObjectStreamException]
private def writeReplace(): Object = {
objString
objString: Unit
this
}

Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/Predef.scala
Expand Up @@ -149,7 +149,7 @@ object Predef extends LowPriorityImplicits {

// miscellaneous -----------------------------------------------------
scala.`package` // to force scala package object to be seen.
scala.collection.immutable.List // to force Nil, :: to be seen.
scala.collection.immutable.List: Unit // to force Nil, :: to be seen.

/** @group aliases */
type Function[-A, +B] = Function1[A, B]
Expand Down
4 changes: 2 additions & 2 deletions src/library/scala/Symbol.scala
Expand Up @@ -67,9 +67,9 @@ private[scala] abstract class UniquenessCache[K, V >: Null] {
// wind up with one String as the key and a different String as
// the name field in the Symbol, which can lead to surprising GC
// behavior and duplicate Symbols. See scala/bug#6706.
map remove name
map.remove(name): Unit
val sym = valueFromKey(name)
map.put(name, new WeakReference(sym))
map.put(name, new WeakReference(sym)): Unit
sym
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/library/scala/collection/ArrayOps.scala
Expand Up @@ -474,9 +474,9 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
def partition(p: A => Boolean): (Array[A], Array[A]) = {
val res1, res2 = ArrayBuilder.make[A]
var i = 0
while(i < xs.length) {
while (i < xs.length) {
val x = xs(i)
(if(p(x)) res1 else res2) += x
(if (p(x)) res1 else res2) += x
i += 1
}
(res1.result(), res2.result())
Expand Down Expand Up @@ -506,11 +506,11 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
val res1 = ArrayBuilder.make[A1]
val res2 = ArrayBuilder.make[A2]
var i = 0
while(i < xs.length) {
f(xs(i)) match {
while (i < xs.length) {
(f(xs(i)) match {
case Left(x) => res1 += x
case Right(x) => res2 += x
}
}): Unit
i += 1
}
(res1.result(), res2.result())
Expand Down Expand Up @@ -1318,15 +1318,15 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
val len = xs.length
var i = 0
(xs: Any @unchecked) match {
case xs: Array[AnyRef] => while (i < len) { f(xs(i).asInstanceOf[A]); i = i+1 }
case xs: Array[Int] => while (i < len) { f(xs(i).asInstanceOf[A]); i = i+1 }
case xs: Array[Double] => while (i < len) { f(xs(i).asInstanceOf[A]); i = i+1 }
case xs: Array[Long] => while (i < len) { f(xs(i).asInstanceOf[A]); i = i+1 }
case xs: Array[Float] => while (i < len) { f(xs(i).asInstanceOf[A]); i = i+1 }
case xs: Array[Char] => while (i < len) { f(xs(i).asInstanceOf[A]); i = i+1 }
case xs: Array[Byte] => while (i < len) { f(xs(i).asInstanceOf[A]); i = i+1 }
case xs: Array[Short] => while (i < len) { f(xs(i).asInstanceOf[A]); i = i+1 }
case xs: Array[Boolean] => while (i < len) { f(xs(i).asInstanceOf[A]); i = i+1 }
case xs: Array[AnyRef] => while (i < len) { f(xs(i).asInstanceOf[A]): Unit ; i = i+1 }
case xs: Array[Int] => while (i < len) { f(xs(i).asInstanceOf[A]): Unit ; i = i+1 }
case xs: Array[Double] => while (i < len) { f(xs(i).asInstanceOf[A]): Unit ; i = i+1 }
case xs: Array[Long] => while (i < len) { f(xs(i).asInstanceOf[A]): Unit ; i = i+1 }
case xs: Array[Float] => while (i < len) { f(xs(i).asInstanceOf[A]): Unit ; i = i+1 }
case xs: Array[Char] => while (i < len) { f(xs(i).asInstanceOf[A]): Unit ; i = i+1 }
case xs: Array[Byte] => while (i < len) { f(xs(i).asInstanceOf[A]): Unit ; i = i+1 }
case xs: Array[Short] => while (i < len) { f(xs(i).asInstanceOf[A]): Unit ; i = i+1 }
case xs: Array[Boolean] => while (i < len) { f(xs(i).asInstanceOf[A]): Unit ; i = i+1 }
}
}

Expand Down Expand Up @@ -1476,7 +1476,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
/** Create a copy of this array with the specified element type. */
def toArray[B >: A: ClassTag]: Array[B] = {
val destination = new Array[B](xs.length)
copyToArray(destination, 0)
copyToArray(destination, 0): Unit
destination
}

Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/IndexedSeqView.scala
Expand Up @@ -36,7 +36,7 @@ trait IndexedSeqView[+A] extends IndexedSeqOps[A, View, View[A]] with SeqView[A]
override def map[B](f: A => B): IndexedSeqView[B] = new IndexedSeqView.Map(this, f)
override def reverse: IndexedSeqView[A] = new IndexedSeqView.Reverse(this)
override def slice(from: Int, until: Int): IndexedSeqView[A] = new IndexedSeqView.Slice(this, from, until)
override def tapEach[U](f: A => U): IndexedSeqView[A] = new IndexedSeqView.Map(this, { (a: A) => f(a); a})
override def tapEach[U](f: A => U): IndexedSeqView[A] = new IndexedSeqView.Map(this, { (a: A) => f(a): Unit; a})

def concat[B >: A](suffix: IndexedSeqView.SomeIndexedSeqOps[B]): IndexedSeqView[B] = new IndexedSeqView.Concat(this, suffix)
def appendedAll[B >: A](suffix: IndexedSeqView.SomeIndexedSeqOps[B]): IndexedSeqView[B] = new IndexedSeqView.Concat(this, suffix)
Expand Down
8 changes: 4 additions & 4 deletions src/library/scala/collection/Iterable.scala
Expand Up @@ -279,7 +279,7 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
val it = iterator
while (it.hasNext) {
if (i == otherSize) return 1
it.next()
it.next(): Unit
i += 1
}
i - otherSize
Expand Down Expand Up @@ -332,8 +332,8 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
val thisIt = this.iterator
val thatIt = that.iterator
while (thisIt.hasNext && thatIt.hasNext) {
thisIt.next()
thatIt.next()
thisIt.next(): Unit
thatIt.next(): Unit
}
java.lang.Boolean.compare(thisIt.hasNext, thatIt.hasNext)
}
Expand Down Expand Up @@ -837,7 +837,7 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
*/
def inits: Iterator[C] = iterateUntilEmpty(_.init)

override def tapEach[U](f: A => U): C = fromSpecific(new View.Map(this, { (a: A) => f(a); a }))
override def tapEach[U](f: A => U): C = fromSpecific(new View.Map(this, { (a: A) => f(a): Unit; a }))

// A helper for tails and inits.
private[this] def iterateUntilEmpty(f: Iterable[A] => Iterable[A]): Iterator[C] = {
Expand Down
6 changes: 3 additions & 3 deletions src/library/scala/collection/IterableOnce.scala
Expand Up @@ -571,7 +571,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
*/
def foreach[U](f: A => U): Unit = {
val it = iterator
while(it.hasNext) f(it.next())
while (it.hasNext) f(it.next()): Unit
}

/** Tests whether a predicate holds for all elements of this $coll.
Expand Down Expand Up @@ -821,7 +821,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
else {
val it = iterator
var len = 0
while (it.hasNext) { len += 1; it.next() }
while (it.hasNext) { len += 1; it.next(): Unit }
len
}
}
Expand Down Expand Up @@ -1291,7 +1291,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
def toArray[B >: A: ClassTag]: Array[B] =
if (knownSize >= 0) {
val destination = new Array[B](knownSize)
copyToArray(destination, 0)
copyToArray(destination, 0): Unit
destination
}
else mutable.ArrayBuilder.make[B].addAll(this).result()
Expand Down
6 changes: 3 additions & 3 deletions src/library/scala/collection/Iterator.scala
Expand Up @@ -449,7 +449,7 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
def indexOf[B >: A](elem: B, from: Int): Int = {
var i = 0
while (i < from && hasNext) {
next()
next(): Unit
i += 1
}

Expand Down Expand Up @@ -949,7 +949,7 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
override def hasNext = self.hasNext
override def next() = {
val _next = self.next()
f(_next)
f(_next): Unit
_next
}
}
Expand Down Expand Up @@ -1223,7 +1223,7 @@ object Iterator extends IterableFactory[Iterator] {
private def skip(): Unit =
while (dropping > 0) {
if (underlying.hasNext) {
underlying.next()
underlying.next(): Unit
dropping -= 1
} else
dropping = 0
Expand Down
6 changes: 3 additions & 3 deletions src/library/scala/collection/LazyZipOps.scala
Expand Up @@ -109,7 +109,7 @@ final class LazyZip2[+El1, +El2, C1] private[collection](src: C1, coll1: Iterabl
val elems1 = coll1.iterator
val elems2 = coll2.iterator

while (elems1.hasNext && elems2.hasNext) f(elems1.next(), elems2.next())
while (elems1.hasNext && elems2.hasNext) f(elems1.next(), elems2.next()): Unit
}

private def toIterable: View[(El1, El2)] = new AbstractView[(El1, El2)] {
Expand Down Expand Up @@ -245,7 +245,7 @@ final class LazyZip3[+El1, +El2, +El3, C1] private[collection](src: C1,
val elems3 = coll3.iterator

while (elems1.hasNext && elems2.hasNext && elems3.hasNext)
f(elems1.next(), elems2.next(), elems3.next())
f(elems1.next(), elems2.next(), elems3.next()): Unit
}

private def toIterable: View[(El1, El2, El3)] = new AbstractView[(El1, El2, El3)] {
Expand Down Expand Up @@ -383,7 +383,7 @@ final class LazyZip4[+El1, +El2, +El3, +El4, C1] private[collection](src: C1,
val elems4 = coll4.iterator

while (elems1.hasNext && elems2.hasNext && elems3.hasNext && elems4.hasNext)
f(elems1.next(), elems2.next(), elems3.next(), elems4.next())
f(elems1.next(), elems2.next(), elems3.next(), elems4.next()): Unit
}

private def toIterable: View[(El1, El2, El3, El4)] = new AbstractView[(El1, El2, El3, El4)] {
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/Map.scala
Expand Up @@ -241,7 +241,7 @@ trait MapOps[K, +V, +CC[_, _] <: IterableOps[_, AnyConstr, _], +C]
val it = iterator
while (it.hasNext) {
val next = it.next()
f(next._1, next._2)
f(next._1, next._2): Unit
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/MapView.scala
Expand Up @@ -146,7 +146,7 @@ object MapView extends MapViewFactory {
override def get(key: K): Option[V] = {
underlying.get(key) match {
case s @ Some(v) =>
f((key, v))
f((key, v)): Unit
s
case None => None
}
Expand Down
6 changes: 3 additions & 3 deletions src/library/scala/collection/Seq.scala
Expand Up @@ -723,7 +723,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any
else if (len > 1) {
b.sizeHint(len)
val arr = new Array[Any](len)
copyToArray(arr)
copyToArray(arr): Unit
java.util.Arrays.sort(arr.asInstanceOf[Array[AnyRef]], ord.asInstanceOf[Ordering[AnyRef]])
var i = 0
while (i < len) {
Expand Down Expand Up @@ -892,7 +892,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any
}
case Some(1) => None
case Some(n) => Some(n - 1)
}
}: Unit
include
})
}
Expand All @@ -917,7 +917,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any
}
case Some(1) => None
case Some(n) => Some(n - 1)
}
}: Unit
include
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/library/scala/collection/SeqView.scala
Expand Up @@ -27,7 +27,7 @@ trait SeqView[+A] extends SeqOps[A, View, View[A]] with View[A] {
override def drop(n: Int): SeqView[A] = new SeqView.Drop(this, n)
override def takeRight(n: Int): SeqView[A] = new SeqView.TakeRight(this, n)
override def dropRight(n: Int): SeqView[A] = new SeqView.DropRight(this, n)
override def tapEach[U](f: A => U): SeqView[A] = new SeqView.Map(this, { (a: A) => f(a); a })
override def tapEach[U](f: A => U): SeqView[A] = new SeqView.Map(this, { (a: A) => f(a): Unit; a })

def concat[B >: A](suffix: SeqView.SomeSeqOps[B]): SeqView[B] = new SeqView.Concat(this, suffix)
def appendedAll[B >: A](suffix: SeqView.SomeSeqOps[B]): SeqView[B] = new SeqView.Concat(this, suffix)
Expand Down Expand Up @@ -163,7 +163,7 @@ object SeqView {
else if (len == 1) List(underlying.head)
else {
val arr = new Array[Any](len) // Array[Any] =:= Array[AnyRef]
underlying.copyToArray(arr)
underlying.copyToArray(arr): Unit
java.util.Arrays.sort(arr.asInstanceOf[Array[AnyRef]], ord.asInstanceOf[Ordering[AnyRef]])
// casting the Array[AnyRef] to Array[A] and creating an ArraySeq from it
// is safe because:
Expand Down
6 changes: 3 additions & 3 deletions src/library/scala/collection/StrictOptimizedIterableOps.scala
Expand Up @@ -259,8 +259,8 @@ trait StrictOptimizedIterableOps[+A, +CC[_], +C]
val lead = iterator drop n
val it = iterator
while (lead.hasNext) {
lead.next()
it.next()
lead.next(): Unit
it.next(): Unit
}
while (it.hasNext) b += it.next()
b.result()
Expand All @@ -277,7 +277,7 @@ trait StrictOptimizedIterableOps[+A, +CC[_], +C]
val it = iterator
while (lead.hasNext) {
b += it.next()
lead.next()
lead.next(): Unit
}
b.result()
}
Expand Down
6 changes: 3 additions & 3 deletions src/library/scala/collection/StringOps.scala
Expand Up @@ -1034,7 +1034,7 @@ final class StringOps(private val s: String) extends AnyVal {
val len = s.length
var i = 0
while(i < len) {
f(s.charAt(i))
f(s.charAt(i)): Unit
i += 1
}
}
Expand Down Expand Up @@ -1437,8 +1437,8 @@ final class StringOps(private val s: String) extends AnyVal {
val len = s.length
while(i < len) {
f(s.charAt(i)) match {
case Left(c) => res1.append(c)
case Right(c) => res2.append(c)
case Left(c) => res1.append(c): Unit
case Right(c) => res2.append(c): Unit
}
i += 1
}
Expand Down

0 comments on commit 28a7770

Please sign in to comment.