combining receive pfs - am I being stupid here?

176 views
Skip to first unread message

Tim Pigden

unread,
Sep 23, 2014, 12:29:08 PM9/23/14
to akka...@googlegroups.com
The following example:

class TestPF extends Actor {

  val x: Receive = {
    case "hi" => sender ! "hello"
  }

  val y: Receive = {
    case "bye" => sender ! "farewell"
  }

  def receive = { x orElse y }

}

gets a warning
Warning:(18, 28) a type was inferred to be `Any`; this may indicate a programming error.
  def receive = { x orElse y }
                           ^

Am I doing something wrong? I thought this was the intended use pattern. Can I make these warnings go away?

Alec Zorab

unread,
Sep 23, 2014, 12:34:09 PM9/23/14
to akka...@googlegroups.com
My workaround:

..in package object ...
  def Rx(r: Receive): Receive = r

//no warnings!
class Act extends Actor {
  val x: Receive = Rx {
    case "hi" => sender ! "hello"
  }

  val y: Receive = Rx {
    case "bye" => sender ! "farewell"
  }

  def receive = Rx {x orElse y}
}

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Adam

unread,
Sep 23, 2014, 4:26:04 PM9/23/14
to akka...@googlegroups.com
Interesting.
Which Scala version are you using?

I've copied your code into a Scala project I have that uses Scala 2.11.2 (with akka 2.3.6) and I get no warnings.
Also the IDE (Intellij) correctly shows that receive is of type PartialFunction[Any,Unit].

Have you tried modifying it to:

def receive: Receive = { x orElse y }

?

I would assume that should cause type inference to be skipped and therefore also make the warning go away, like in the previous answer.

Tim Pigden

unread,
Sep 23, 2014, 6:15:39 PM9/23/14
to akka-user@googlegroups com
2.11.2 (akka 2.3.4)

scalacOptions := Seq("-feature", "-deprecation", "-encoding", "utf8", "-Xlint")

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/0rkUCQxru5I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Tim Pigden
Optrak Distribution Software Limited
+44 (0)1992 517100
http://www.linkedin.com/in/timpigden
http://optrak.com
Optrak Distribution Software Ltd is a limited company registered in England and Wales.
Company Registration No. 2327613 Registered Offices: Suite 6,The Maltings, Hoe Lane, Ware, SG12 9LR England 
This email and any attachments to it may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of Optrak Distribution Software Ltd. If you are not the intended recipient of this email, you must neither take any action based upon its contents, nor copy or show it to anyone. Please contact the sender if you believe you have received this email in error.

Tim Pigden

unread,
Sep 23, 2014, 6:16:51 PM9/23/14
to akka-user@googlegroups com
sorry meant to add - yes with or without { } it has the same and just changing now to 2.3.6 it makes no different

Tim Pigden

unread,
Sep 23, 2014, 6:30:57 PM9/23/14
to akka...@googlegroups.com
seems to be to do with the Xlint option
To unsubscribe from this group and all its topics, send an email to akka-user+unsubscribe@googlegroups.com.

To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
--
Tim Pigden
Optrak Distribution Software Limited
+44 (0)1992 517100
http://www.linkedin.com/in/timpigden
http://optrak.com
Optrak Distribution Software Ltd is a limited company registered in England and Wales.
Company Registration No. 2327613 Registered Offices: Suite 6,The Maltings, Hoe Lane, Ware, SG12 9LR England 
This email and any attachments to it may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of Optrak Distribution Software Ltd. If you are not the intended recipient of this email, you must neither take any action based upon its contents, nor copy or show it to anyone. Please contact the sender if you believe you have received this email in error.

Adam

unread,
Sep 24, 2014, 1:00:07 AM9/24/14
to akka...@googlegroups.com
I think you can assume this is some kind of bug.
According to the definition of Receive it's equivalent to PartialFunction[Any, Unit] and yet, the following generates no warning (changed the declared return type of y):

class TestPF extends Actor {

  val x
: Receive = {
   
case "hi" => sender ! "hello"
 
}


  val y
: PartialFunction[Any, Unit] = {

   
case "bye" => sender ! "farewell"
 
}

 
def receive = x orElse y

}

So you should probably open a Scala bug for this, if there isn't already one.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
--
Tim Pigden
Optrak Distribution Software Limited
+44 (0)1992 517100
http://www.linkedin.com/in/timpigden
http://optrak.com
Optrak Distribution Software Ltd is a limited company registered in England and Wales.
Company Registration No. 2327613 Registered Offices: Suite 6,The Maltings, Hoe Lane, Ware, SG12 9LR England 
This email and any attachments to it may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of Optrak Distribution Software Ltd. If you are not the intended recipient of this email, you must neither take any action based upon its contents, nor copy or show it to anyone. Please contact the sender if you believe you have received this email in error.

Tim Pigden

unread,
Sep 24, 2014, 2:53:49 AM9/24/14
to akka-user@googlegroups com
eported as 8661

Eugene Platonov

unread,
Apr 29, 2015, 3:02:09 PM4/29/15
to akka...@googlegroups.com
Hi Tim, could you send a link to the issue you created?
Thanks

Som Snytt

unread,
Apr 29, 2015, 4:05:29 PM4/29/15
to akka...@googlegroups.com
but the commit was just a partial fix (as opposed to a total fix).

https://github.com/scala/scala/pull/4375

You can also turn off the warning -Xlint:-infer-any

You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages