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

Re: Oddity trying to import members of an object?

2 replies
Robin Barooah
Joined: 2008-12-21,
User offline. Last seen 3 years 27 weeks ago.
So I managed to answer my own question.
Using scalap, I see:
Garuda:target robin$ scalap -cp $TCLASS -verbose org.sublime.amazon.simpleDB.QueryCLASSPATH = /Users/robin/src/simpleDB-scala-binding/target/classes FILENAME = /Users/robin/src/simpleDB-scala-binding/target/classes/org/sublime/amazon/simpleDB/Query.classpackage org.sublime.amazon.simpleDB;abstract trait Query with scala.ScalaObject with org.sublime.amazon.simpleDB.SimpleDBRequest {   def action(): java.lang.String;  def maxNumberOfItems(): scala.Option;  def nextToken(): scala.Option;  def queryExpression(): scala.Option;  def domainName(): java.lang.String;   def specificParameters(): scala.collection.immutable.Map;}
It turns out that I have a trait called Query in the same package as my object Query.
Not sure what happens to the Object in this case, the compiler didn't object but the object appears to be shadowed or just plain disappeared.
-Robin
On Fri, Dec 26, 2008 at 11:32 PM, Robin <robin [at] sublime [dot] org> wrote:
Hi,
I've been having trouble importing the members of an object, which is something I do all the time.  It's entirely possible I've gone code-blind over the holidays, but this is really stumping me.
The source looks like this:
package org.sublime.amazon.simpleDB {         object Query {                 abstract case class Expression {            //def query :String         }...
Which compiles fine. From the console (with the classpath set correctly by mvn scala:console), I do this:
scala> import org.sublime.amazon.simpleDB.Query._ import org.sublime.amazon.simpleDB.Query._<console>:4: error: value Query is not a member of package org.sublime.amazon.simpleDB        import org.sublime.amazon.simpleDB.Query._                                          ^
scala> import org.sublime.amazon.simpleDB.Query   import org.sublime.amazon.simpleDB.Query
As you can see, my attempt to import the members of Query fails with "Query is not a member of package...", and yet my attempt to import Query itself succeeds, so there's clearly something there.
Am I missing something obvious here?
The full source of Query.scala is here: http://github.com/rbarooah/simpledb-scala-binding/tree/17cb3a8799d40e388a64f617296a81a9472ae3e3/src/main/scala/org/sublime/amazon/simpleDB/Query.scala 

And you can reproduce the problem by doing:
git clone git://github.com/rbarooah/simpledb-scala-binding.git broken cd brokenmvn compile scala:console
And then attempting the import.
Please tell me it's code blindness and I've missed something obvious!  Any insight gladly appreciated.
Thanks.
--
-Robin

Robin Barooah
http://www.sublime.org



--
-Robin

Robin Barooah
http://www.sublime.org
David Hall
Joined: 2008-12-28,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Oddity trying to import members of an object?

I have no problem with your code:

scala> import org.sublime.amazon.simpleDB.Query._
import org.sublime.amazon.simpleDB.Query._
import org.sublime.amazon.simpleDB.Query._

scala>

As for scalap, scala appends "$" to the end of objects in the
generated jvm code:

Macintosh-107:broken dlwh$ javap -classpath target/classes
org.sublime.amazon.simpleDB.Query$
Compiled from "Query.scala"
public final class org.sublime.amazon.simpleDB.Query$ extends
java.lang.Object implements scala.ScalaObject{
public static final org.sublime.amazon.simpleDB.Query$ MODULE$;
public static {};
public org.sublime.amazon.simpleDB.Query$();
public org.sublime.amazon.simpleDB.Query$Attribute
attribute(java.lang.String, org.sublime.amazon.simpleDB.Conversion);
public org.sublime.amazon.simpleDB.Query$Attribute
attribute(java.lang.String);
public int $tag() throws java.rmi.RemoteException;
}

So, in short, I'm afraid I can't reproduce your problem, and your
explanation isn't right. :)

Robin Barooah
Joined: 2008-12-21,
User offline. Last seen 3 years 27 weeks ago.
Re: Re: Oddity trying to import members of an object?

I pushed the fix to my github repository about 6 hours ago, but left
my explanation email open in a tab in gmail without sending - sorry!

But thanks for trying to reproduce it.

-Robin

On Dec 27, 2008, at 8:48 PM, David Hall wrote:

> I have no problem with your code:
>
> scala> import org.sublime.amazon.simpleDB.Query._
> import org.sublime.amazon.simpleDB.Query._
> import org.sublime.amazon.simpleDB.Query._
>
> scala>
>
> As for scalap, scala appends "$" to the end of objects in the
> generated jvm code:
>
> Macintosh-107:broken dlwh$ javap -classpath target/classes
> org.sublime.amazon.simpleDB.Query$
> Compiled from "Query.scala"
> public final class org.sublime.amazon.simpleDB.Query$ extends
> java.lang.Object implements scala.ScalaObject{
> public static final org.sublime.amazon.simpleDB.Query$ MODULE$;
> public static {};
> public org.sublime.amazon.simpleDB.Query$();
> public org.sublime.amazon.simpleDB.Query$Attribute
> attribute(java.lang.String, org.sublime.amazon.simpleDB.Conversion);
> public org.sublime.amazon.simpleDB.Query$Attribute
> attribute(java.lang.String);
> public int $tag() throws java.rmi.RemoteException;
> }
>
> So, in short, I'm afraid I can't reproduce your problem, and your
> explanation isn't right. :)
>

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