... ). Option can be Some or None" />

Scala warning match may not be exhaustive

Scala warning match may not be exhaustive

By : user2954000
Date : November 21 2020, 07:31 AM
like below fixes the issue When pattern matching, you should account for all possible cases or provide a "fallback" (case _ => ... ). Option can be Some or None, but you're only matching against the None case.
If Session.get().getAttribute("player") returned Some(player) you would get a MatchError (exception).
code :
if(Option(Session.get().getAttribute("player")).isEmpty) {
    val player = new Player(user.getEmail, user.getNickname).createOrGet
    Session.get().setAttribute("player", player)

Share : facebook icon twitter icon
Why does Scala 2.10 give 'match may not be exhaustive' warning when matching on singleton types?

Why does Scala 2.10 give 'match may not be exhaustive' warning when matching on singleton types?

By : Dazed and Confused
Date : March 29 2020, 07:55 AM
wish of those help And it's been patched, c.f. https://github.com/retronym/scala/compare/ticket/5968.
Scala: Incorrect warning "match may not be exhaustive"

Scala: Incorrect warning "match may not be exhaustive"

By : Constandache Daniela
Date : March 29 2020, 07:55 AM
hop of those help? I suppose it's because the type given to bar is the supertype (bar could be a B1 or B2 and the only common type is Bar), so theoretically it could still be a B3 and the compiler is not smart enough for this:
code :
def foo(a:A) = a match {
  case A(bar@(B1|B2)) =>
    bar match { // bar here has a Bar type
        case B1 => 
        case B2 => 
  case _ =>
Scala warning match may not be exhaustive while parsing

Scala warning match may not be exhaustive while parsing

By : W Li
Date : March 29 2020, 07:55 AM
I wish this help you The issue here is that with ("+" | "-") you are creating a parser that accepts only two possible strings. However when you map on the resulting parser to extract the value, the result you're going to extract will just be String.
In your pattern matching you only have cases for the strings "+" and "-", but the compiler has no way of knowing that those are the only possible strings that will show up, so it's telling you here that your match may not be exhaustive since it can't know any better.
code :
sealed trait Operation
case object Plus extends Operation
case object Minus extends Operation

//then in your parser
("+" ^^^ Plus | "-" ^^^ Minus) ~ term ^^ {
  case PLus ~ t => t
  case Minus ~ t  => -t
How to suppress the "match may not be exhaustive" warning in Scala?

How to suppress the "match may not be exhaustive" warning in Scala?

By : KJ JK
Date : March 29 2020, 07:55 AM
it fixes the issue You could use the unchecked annotation:
code :
(t: @unchecked) match {
  case STRING => ???
  case NUMERIC => ???
  case BOOLEAN => ???
How should I handle 'match may not be exhaustive' warning in Scala?

How should I handle 'match may not be exhaustive' warning in Scala?

By : user3489585
Date : March 29 2020, 07:55 AM
will help you In this case, your operation fails if the input is Nil. If you know the list can not be empty, you can use the NonEmptyList type from cats: https://typelevel.org/cats/api/cats/data/NonEmptyList.html. Otherwise, you can use a pattern match to more clearly express your intent in that case, something like:
code :
val (head, tail) = factories match {
  case h :: t => (h,t)
  case Nil => ??? //Process empty list however you like
Related Posts Related Posts :
  • Assign generic method to variable in Scala
  • General Finite State Machine (Transducer) in Scala
  • What is the usage of a final var in Scala
  • Define Generic Types with String
  • Why there is a ClassCastException when isInstanceOf returns true on a scala type with wildcard parameter?
  • How to reaload scala application after code change using actors and sbt
  • akka non-blocking BoundedMailbox
  • Why are constructor parameters made into members for case classes?
  • Higher order tail recursive function needs to terminate early
  • How can I reusably filter based on type in Scala?
  • Why does Scala sbt update every time I start it from command prompt?
  • Recommended Scala io library
  • Thread-safely transforming a value in a mutable map
  • Why does chaining match expressions does not compile?
  • Ebean not persisting foreign keys
  • Difference between def m(p: T forSome {type T} and def m1(p:Any), is there any ? Explanation needed based on Scala Langu
  • macro does not find out enclosing vals
  • Spark : how to run spark file from spark shell
  • Flattening a list of lists to a set with exceptions in scala
  • flatMap implementation in Scala
  • Confused about a few lines code in a scala official document page
  • How to input parameters when running bash command with Scala
  • Location header is lost if max-redirects > 1
  • Controller Spec is using FakeApplication, but can't load test configuration
  • Scala code analyzer targets case variable names that are identical to the outer matched varables - "suspicous shado
  • Why does authorize directive execute after the code it's supposed to protect?
  • Scala. Checking if a Type is Comparable
  • Does having a private constructor on a value class negate the benefits of a value class?
  • How to transform submitted json in Play 2.0?
  • Pure not a member of objective Promise in PlayFramework
  • How to unmarshal POST params and JSON body in a single route?
  • Spark:How to use join method?
  • is client thread-safe in Twitter Finagle
  • Why is the method accepts only one argument?
  • Scala Play 2.3 Working with gCloud Storage - any libs to go async?
  • spray.io strange get/delete/detach directives behavior
  • SBT cannot resolve class declared in src/main/scala in a src/test/scala test class
  • Scala typeclass without function argument
  • Configuring actor behavior using typesafe Config and HOCON
  • Scalatra: Migrating Jersey Filters to Scalatra
  • Compilation error when using Scaldi
  • Scalac hanging in phase typer
  • how to have different source code when cross-compiling Scala with sbt? (changes in MurmurHash)
  • How to set different scalacOptions per Scala version when cross-compiling using Build.scala?
  • Possible Bug in JDBC?
  • Is there a Scala compiler flag to warn when tail recursion is applied without annotation?
  • scala case class put methods in companion object?
  • multiproject sbt doesn't generate file structure
  • Scala "multilevel" abstract class / abstract objects replacement
  • Scala, getting the type parameters of a KList as an HList
  • Why does Play refuse form reporting "Cannot resolve method apply with such signature: Missing arguments"?
  • How to split string with trailing empty strings in result?
  • Scala group by list of list and subtracts grouped values
  • Scala - Creating a function to produce Unary string or integer values
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org