Scala

Scala

Made by DeepSource

Missing case None in pattern-matching SC-W1025

Bug risk
Critical

Analyzer has detected that the case Some(_) was specified in the pattern-matching but not None. The general consensus is that any method that wraps a value in Some usually has a return type of Option[T]. In case the method succeeds, Some(_) is returned, else None. Therefore it is recommended that you add the missing case None in your pattern-matching.

Bad practice

hashmap.get(key) match {
  case Some(value) => println(s"value of $key is $value")
}

Recommended

hashmap.get(key) match {
  case Some(value) => println(s"value of $key is $value")
  case None => println(s"$key is not in the hashmap!")
}