This page is no longer maintained — Please continue to the home page at www.scala-lang.org

"Double dispatch" issue of inherited trait method with sequence args when used from different package within a for comprehension

2 replies
Chris Marshall
Joined: 2009-06-17,
User offline. Last seen 44 weeks 3 days ago.
.hmmessage P { margin:0px; padding:0px } body.hmmessage { font-size: 10pt; font-family:Verdana } I have a trait Logged which declares a method infof thus: 
  protected def infof(msg: String, os: Any*) = if (log.isLoggable(Level.INFO)) {    log.log(Level.INFO, msg.format(os : _ *))
  }
I have test class which is declared as follows (*in a different package*): 
class LoggedTest extends Logged { //this is line 13
  def someMethod(): Unit = {    infof("Here is a tuple %s and a boolean %s", (1, "Hello"), false) //works    for (tu <- TimeUnit.values) {        infof("Here is a tuple %s and a boolean %s", (tu.name, "Hello"), true) //this is line 17 - throws Exception    }  }}

Basically this is throwing a runtime MissingFormatArgument exception at line 17, which is odd because this call to infof looks exactly like the previous one on line 15, which proceeded just fine. 
1. *Everything works if I declare LoggedTest in the same package as Logged*2. *Everything works fine if I declare infof to be a public method*
The reason for the failure is the bold lines in the below stack trace: the call to infof seems to be duplicated and my infof method is ultimately being called with an Array with one element (that element is itself an Array with 2 elements). If I declare my tests in the same package as Logged then I don't see the "protected$infof" duplicate call in the stack.
at myutil.Logged$class.infof(Logged.scala:86) at mytest.LoggedTest.infof(LoggedTest.scala:13) at mytest.LoggedTest.protected$infof(LoggedTest.scala:17) at mytest.LoggedTest$$anonfun$someMethod$1.apply(LoggedTest.scala:17) at mytest.LoggedTest$$anonfun$someMethod$1.apply(LoggedTest.scala:16) at scala.Iterator$class.foreach(Iterator.scala:414)
Is this a bug in the scala compiler that when it "double-dispatches" due to package differences, it doesn't treat sequences properly (when in for comprehensions)?
Chris
View your Twitter and Flickr updates from one place – Learn more!
Ricky Clarkson
Joined: 2008-12-19,
User offline. Last seen 3 years 2 weeks ago.
Re: "Double dispatch" issue of inherited trait method with seq

Yes, that's a bug. I'd report it in Trac - http://lampsvn.epfl.ch/trac/scala

2009/6/25 christopher marshall :
> I have a trait Logged which declares a method infof thus:
>   protected def infof(msg: String, os: Any*) = if
> (log.isLoggable(Level.INFO)) {
>     log.log(Level.INFO, msg.format(os : _ *))
>   }
> I have test class which is declared as follows (*in a different package*):
> class LoggedTest extends Logged { //this is line 13
>   def someMethod(): Unit = {
>     infof("Here is a tuple %s and a boolean %s", (1, "Hello"), false)
> //works
>     for (tu <- TimeUnit.values) {
>         infof("Here is a tuple %s and a boolean %s", (tu.name, "Hello"),
> true) //this is line 17 - throws Exception
>     }
>   }
> }
>
> Basically this is throwing a runtime MissingFormatArgument exception at line
> 17, which is odd because this call to infof looks exactly like the previous
> one on line 15, which proceeded just fine.
> 1. *Everything works if I declare LoggedTest in the same package as Logged*
> 2. *Everything works fine if I declare infof to be a public method*
> The reason for the failure is the bold lines in the below stack trace: the
> call to infof seems to be duplicated and my infof method is ultimately being
> called with an Array with one element (that element is itself an Array with
> 2 elements). If I declare my tests in the same package as Logged then I
> don't see the "protected$infof" duplicate call in the stack.
> at myutil.Logged$class.infof(Logged.scala:86) at
> mytest.LoggedTest.infof(LoggedTest.scala:13) at
> mytest.LoggedTest.protected$infof(LoggedTest.scala:17) at
> mytest.LoggedTest$$anonfun$someMethod$1.apply(LoggedTest.scala:17) at
> mytest.LoggedTest$$anonfun$someMethod$1.apply(LoggedTest.scala:16) at
> scala.Iterator$class.foreach(Iterator.scala:414)
> Is this a bug in the scala compiler that when it "double-dispatches" due to
> package differences, it doesn't treat sequences properly (when in for
> comprehensions)?
> Chris
> ________________________________
> View your Twitter and Flickr updates from one place – Learn more!

Chris Marshall
Joined: 2009-06-17,
User offline. Last seen 44 weeks 3 days ago.
RE: "Double dispatch" issue of inherited trait method with seq
.hmmessage P { margin:0px; padding:0px } body.hmmessage { font-size: 10pt; font-family:Verdana } Bug #2093

> From: ricky.clarkson@gmail.com
> Date: Thu, 25 Jun 2009 13:03:03 +0100
> Subject: Re: [scala-user] "Double dispatch" issue of inherited trait method with sequence args when used from different package within a for comprehension
> To: oxbow_lakes@hotmail.com
> CC: scala-user@listes.epfl.ch
>
> Yes, that's a bug. I'd report it in Trac - http://lampsvn.epfl.ch/trac/scala
>
> 2009/6/25 christopher marshall <oxbow_lakes@hotmail.com>:
> > I have a trait Logged which declares a method infof thus:
> >   protected def infof(msg: String, os: Any*) = if
> > (log.isLoggable(Level.INFO)) {
> >     log.log(Level.INFO, msg.format(os : _ *))
> >   }
> > I have test class which is declared as follows (*in a different package*):
> > class LoggedTest extends Logged { //this is line 13
> >   def someMethod(): Unit = {
> >     infof("Here is a tuple %s and a boolean %s", (1, "Hello"), false)
> > //works
> >     for (tu <- TimeUnit.values) {
> >         infof("Here is a tuple %s and a boolean %s", (tu.name, "Hello"),
> > true) //this is line 17 - throws Exception
> >     }
> >   }
> > }
> >
> > Basically this is throwing a runtime MissingFormatArgument exception at line
> > 17, which is odd because this call to infof looks exactly like the previous
> > one on line 15, which proceeded just fine.
> > 1. *Everything works if I declare LoggedTest in the same package as Logged*
> > 2. *Everything works fine if I declare infof to be a public method*
> > The reason for the failure is the bold lines in the below stack trace: the
> > call to infof seems to be duplicated and my infof method is ultimately being
> > called with an Array with one element (that element is itself an Array with
> > 2 elements). If I declare my tests in the same package as Logged then I
> > don't see the "protected$infof" duplicate call in the stack.
> > at myutil.Logged$class.infof(Logged.scala:86) at
> > mytest.LoggedTest.infof(LoggedTest.scala:13) at
> > mytest.LoggedTest.protected$infof(LoggedTest.scala:17) at
> > mytest.LoggedTest$$anonfun$someMethod$1.apply(LoggedTest.scala:17) at
> > mytest.LoggedTest$$anonfun$someMethod$1.apply(LoggedTest.scala:16) at
> > scala.Iterator$class.foreach(Iterator.scala:414)
> > Is this a bug in the scala compiler that when it "double-dispatches" due to
> > package differences, it doesn't treat sequences properly (when in for
> > comprehensions)?
> > Chris
> > ________________________________
> > View your Twitter and Flickr updates from one place – Learn more!
>
>
>
> --
> Ricky Clarkson
> Java Programmer, AD Holdings
> +44 1565 770804
> Skype: ricky_clarkson
> Google Talk: ricky.clarkson@gmail.com

View your Twitter and Flickr updates from one place – Learn more!

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland