All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wartremover.warts.RedundantAsInstanceOf.scala Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
package org.wartremover
package warts

object RedundantAsInstanceOf extends WartTraverser {
  def apply(u: WartUniverse): u.Traverser = {
    new u.Traverser(this) {
      import q.reflect.*
      override def traverseTree(tree: Tree)(owner: Symbol): Unit = {
        tree match {
          case _ if hasWartAnnotation(tree) =>
          case _ if tree.isExpr =>
            tree.asExpr match {
              case '{
                    type t1
                    type t2
                    ($x: `t1`).asInstanceOf[`t2`]
                  } if TypeRepr.of[t1].widen =:= TypeRepr.of[t2] && sourceCodeContains(tree, "asInstanceOf") =>
                error(tree.pos, "redundant asInstanceOf")
              case _ =>
                super.traverseTree(tree)(owner)
            }
          case _ =>
            super.traverseTree(tree)(owner)
        }
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy