object NonUnitForEach extends WartTraverser
This wart warns when methods scala.collection.IterableOnceOps.foreach and
scala.collection.IterableOnceOps.tapEach are used with non-unit valued functions.
This is needed because these methods' signature accepts any-valued functions.
So -Ywarn-value-discard
does not warn about such discarded values.
scala.collection.IterableOnceOps.foreach is also used in for
loops without yield
and therefore also covers cases such as for { x <- 1 to 10 } { x + 5 }
.
Builder operations such as b += ...
are identified by their return type this.type
and ignored when checking for non-unit return values. This allows common usages such
as for { x <- 1 to 10 } { b += x }
and
for { x <- 1 to 10 } { if (x % 2 == 0) b += x }
.
This does not work for all usages though; you can force a Unit
type by
specifying the type argument of scala.collection.IterableOnceOps.foreach and
scala.collection.IterableOnceOps.tapEach as in (1 to 10).foreach[Unit] { ... }
,
or by ascribing Unit
as in (1 to 10).foreach { x => f(x): Unit }
,
or by explicitly discarding the result: (1 to 10).foreach { x => f(x).discard }
.
- Alphabetic
- By Inheritance
- NonUnitForEach
- WartTraverser
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def apply(u: WartUniverse): Traverser
- Definition Classes
- NonUnitForEach → WartTraverser
- def asAnnotationMacro(c: Context)(annottees: scala.reflect.macros.blackbox.Context.Expr[Any]*): scala.reflect.macros.blackbox.Context.Expr[Any]
- Definition Classes
- WartTraverser
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def asMacro(c: Context)(expr: scala.reflect.macros.blackbox.Context.Expr[Any]): scala.reflect.macros.blackbox.Context.Expr[Any]
- Definition Classes
- WartTraverser
- lazy val className: String
- Definition Classes
- WartTraverser
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- def compose(o: WartTraverser): WartTraverser
- Definition Classes
- WartTraverser
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def error(u: WartUniverse)(pos: scala.reflect.api.Universe.Position, message: String): Unit
- Definition Classes
- WartTraverser
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hasTypeAscription(u: WartUniverse)(tree: scala.reflect.api.Universe.ValOrDefDef): Boolean
- Definition Classes
- WartTraverser
- def hasWartAnnotation(u: WartUniverse)(tree: scala.reflect.api.Universe.Tree): Boolean
- Definition Classes
- WartTraverser
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def isAnonymousFunctionName(u: WartUniverse)(t: scala.reflect.api.Universe.TypeName): Boolean
- Definition Classes
- WartTraverser
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isPrimitive(u: WartUniverse)(t: scala.reflect.api.Universe.Type): Boolean
- Definition Classes
- WartTraverser
- def isPrivate(u: WartUniverse)(t: scala.reflect.api.Universe.ValOrDefDef): Boolean
- Definition Classes
- WartTraverser
- def isPublic(u: WartUniverse)(t: scala.reflect.api.Universe.ValOrDefDef): Boolean
- Definition Classes
- WartTraverser
- def isSynthetic(u: WartUniverse)(t: scala.reflect.api.Universe.Tree): Boolean
- Definition Classes
- WartTraverser
- def isSyntheticPartialFunction(u: WartUniverse)(tree: scala.reflect.api.Universe.Tree): Boolean
- Definition Classes
- WartTraverser
- def isWartAnnotation(u: WartUniverse)(a: scala.reflect.api.Universe.Annotation): Boolean
- Definition Classes
- WartTraverser
- val messageAppliedForeach: String
- val messageUnappliedForeach: String
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- def warning(u: WartUniverse)(pos: scala.reflect.api.Universe.Position, message: String): Unit
- Definition Classes
- WartTraverser
- lazy val wartName: String
- Definition Classes
- WartTraverser
- def wasInferred(u: WartUniverse)(t: scala.reflect.api.Universe.TypeTree): Boolean
- Definition Classes
- WartTraverser