- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
"Double dispatch" issue of inherited trait method with sequence args when used from different package within a for comprehension
Thu, 2009-06-25, 12:57
.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!
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!
Thu, 2009-06-25, 16:07
#2
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!
> 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!
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!