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

Problems with scala package

5 replies
Amador Cuenca
Joined: 2010-08-12,
User offline. Last seen 1 year 30 weeks ago.
Hi all, I've a dummy question.

I've this class in a file:

 case class Bit(v: Boolean) {
    private var value: Boolean = v
    def getValue: Boolean = value
    def setValue(v: Boolean): Unit = if (v != value) value = v   
   
    def AND(b: Bit): Bit = Bit(this.value & b.getValue)
    def OR(b: Bit): Bit = Bit(this.value | b.getValue)
  }

And I've this object in another file:

object Test {
  def NOT(b: Bit): Bit = Bit(!b.getValue)
 
  def main(args: Array[String]): Unit = {
    val b1, b2, b3, b4: Bit = Bit(true)
    println(b1 AND b2)
    println(NOT(b1) AND b2 OR b3)
  }
}

Those files are into the same package. But I can't reference it. The follow error appear:

init:
deps-jar:
Compiling 1 source file to /media/ACUENCA/Labs/Test/build/classes
No known dependencies. Compiling everything
/media/ACUENCA/Labs/Test/src/Demo/Circuit/Test.scala:4: error: not found: type Bit
  def NOT(b: Bit): Bit = Bit(!b.getValue)
/media/ACUENCA/Labs/Test/src/Demo/Circuit/Test.scala:4: error: not found: type Bit
  def NOT(b: Bit): Bit = Bit(!b.getValue)
/media/ACUENCA/Labs/Test/src/Demo/Circuit/Test.scala:4: error: not found: value Bit
  def NOT(b: Bit): Bit = Bit(!b.getValue)
/media/ACUENCA/Labs/Test/src/Demo/Circuit/Test.scala:7: error: not found: type Bit
    val b1, b2, b3, b4: Bit = Bit(true)
/media/ACUENCA/Labs/Test/src/Demo/Circuit/Test.scala:7: error: not found: value Bit
    val b1, b2, b3, b4: Bit = Bit(true)
5 errors found
/media/ACUENCA/Labs/Test/nbproject/build-impl.xml:418: The following error occurred while executing this line:
/media/ACUENCA/Labs/Test/nbproject/build-impl.xml:233: Compilation failed because of an internal compiler error; see the error output for details.
GENERACIÓN INCORRECTA (total time: 8 seconds)

But, If I put it all together It works!

object Test {
  def NOT(b: Bit): Bit = Bit(!b.getValue)

  case class Bit(v: Boolean) {
    private var value: Boolean = v
    def getValue: Boolean = value
    def setValue(v: Boolean): Unit = if (v != value) value = v   
   
    def AND(b: Bit): Bit = Bit(this.value & b.getValue)
    def OR(b: Bit): Bit = Bit(this.value | b.getValue)
  }

  def main(args: Array[String]): Unit = {
    val b1, b2, b3, b4: Bit = Bit(true)
    println(b1 AND b2)
    println(NOT(b1) AND b2 OR b3)
  }
}

I hope that someone could help me, I'll appreciate it.

Regards,
--
TSU. Amador Cuenca
jodersky
Joined: 2009-03-17,
User offline. Last seen 1 year 4 weeks ago.
Re: Problems with scala package
Are you sure they're in the same package? Check that the package declaration at the beginning of the source files is the same.
Are you using eclipse? I once refactored a class from one package to another in eclipse and my code wouldn't compile. It turned out that eclipse just moved my source file to another directory but didn't change the package declaration itself.


On 9 September 2010 16:16, Amador Antonio Cuenca <sphi02ac [at] gmail [dot] com> wrote:
Hi all, I've a dummy question.

I've this class in a file:

 case class Bit(v: Boolean) {
    private var value: Boolean = v
    def getValue: Boolean = value
    def setValue(v: Boolean): Unit = if (v != value) value = v   
   
    def AND(b: Bit): Bit = Bit(this.value & b.getValue)
    def OR(b: Bit): Bit = Bit(this.value | b.getValue)
  }

And I've this object in another file:

object Test {
  def NOT(b: Bit): Bit = Bit(!b.getValue)
 
  def main(args: Array[String]): Unit = {
    val b1, b2, b3, b4: Bit = Bit(true)
    println(b1 AND b2)
    println(NOT(b1) AND b2 OR b3)
  }
}

Those files are into the same package. But I can't reference it. The follow error appear:

init:
deps-jar:
Compiling 1 source file to /media/ACUENCA/Labs/Test/build/classes
No known dependencies. Compiling everything
/media/ACUENCA/Labs/Test/src/Demo/Circuit/Test.scala:4: error: not found: type Bit
  def NOT(b: Bit): Bit = Bit(!b.getValue)
/media/ACUENCA/Labs/Test/src/Demo/Circuit/Test.scala:4: error: not found: type Bit
  def NOT(b: Bit): Bit = Bit(!b.getValue)
/media/ACUENCA/Labs/Test/src/Demo/Circuit/Test.scala:4: error: not found: value Bit
  def NOT(b: Bit): Bit = Bit(!b.getValue)
/media/ACUENCA/Labs/Test/src/Demo/Circuit/Test.scala:7: error: not found: type Bit
    val b1, b2, b3, b4: Bit = Bit(true)
/media/ACUENCA/Labs/Test/src/Demo/Circuit/Test.scala:7: error: not found: value Bit
    val b1, b2, b3, b4: Bit = Bit(true)
5 errors found
/media/ACUENCA/Labs/Test/nbproject/build-impl.xml:418: The following error occurred while executing this line:
/media/ACUENCA/Labs/Test/nbproject/build-impl.xml:233: Compilation failed because of an internal compiler error; see the error output for details.
GENERACIÓN INCORRECTA (total time: 8 seconds)

But, If I put it all together It works!

object Test {
  def NOT(b: Bit): Bit = Bit(!b.getValue)

  case class Bit(v: Boolean) {
    private var value: Boolean = v
    def getValue: Boolean = value
    def setValue(v: Boolean): Unit = if (v != value) value = v   
   
    def AND(b: Bit): Bit = Bit(this.value & b.getValue)
    def OR(b: Bit): Bit = Bit(this.value | b.getValue)
  }

  def main(args: Array[String]): Unit = {
    val b1, b2, b3, b4: Bit = Bit(true)
    println(b1 AND b2)
    println(NOT(b1) AND b2 OR b3)
  }
}

I hope that someone could help me, I'll appreciate it.

Regards,
--
TSU. Amador Cuenca

Amador Cuenca
Joined: 2010-08-12,
User offline. Last seen 1 year 30 weeks ago.
Re: Problems with scala package
I'm using Netbeans with the scala plugin.

Look at the complete structure:

//Main.scala file
package comcircuit

object Main {

  def NOT(b: Bit): Bit = Bit(!b.getValue)

  def main(args: Array[String]): Unit = {
    val b1, b2, b3, b4: Bit = Bit(true)
    println(b1 AND b2)
    println(NOT(b1) AND b2 OR b3)
  }

}

//Bit.scala file
package comcircuit

case class Bit(v: Boolean) {
  private var value: Boolean = v
  def getValue: Boolean = value
  def setValue(v: Boolean): Unit = if (v != value) value = v

  def AND(b: Bit): Bit = Bit(this.value & b.getValue)
  def OR(b: Bit): Bit = Bit(this.value | b.getValue)
}

I created a new project with just these 2 files and it don't works!

I have included a screenshot. You can see the netbean project and the files.

Regards,
--
TSU. Amador Cuenca
jodersky
Joined: 2009-03-17,
User offline. Last seen 1 year 4 weeks ago.
Re: Problems with scala package
oops, replied to wrong address again :@

It works fine under eclipse. I don't know much about NetBeans, is it ok to have a period (.) in the project name? Could this maybe lead to some wrong project configuration?
Try cleaning your project. If it doesn't work I'm afraid I won't be able to help you any further.
--Jakob

On 9 September 2010 16:47, Amador Antonio Cuenca <sphi02ac [at] gmail [dot] com> wrote:
I'm using Netbeans with the scala plugin.

Look at the complete structure:

//Main.scala file
package comcircuit

object Main {

  def NOT(b: Bit): Bit = Bit(!b.getValue)

  def main(args: Array[String]): Unit = {
    val b1, b2, b3, b4: Bit = Bit(true)
    println(b1 AND b2)
    println(NOT(b1) AND b2 OR b3)
  }

}

//Bit.scala file
package comcircuit

case class Bit(v: Boolean) {
  private var value: Boolean = v
  def getValue: Boolean = value
  def setValue(v: Boolean): Unit = if (v != value) value = v

  def AND(b: Bit): Bit = Bit(this.value & b.getValue)
  def OR(b: Bit): Bit = Bit(this.value | b.getValue)
}

I created a new project with just these 2 files and it don't works!

I have included a screenshot. You can see the netbean project and the files.

Regards,
--
TSU. Amador Cuenca

Amador Cuenca
Joined: 2010-08-12,
User offline. Last seen 1 year 30 weeks ago.
Re: Problems with scala package
Well,

The problem is with netbeans, I've to clean & build the project. Then, It works. I think it's some plugin's bug.

Thanks for answer shortly.

Regards,

--
TSU. Amador Cuenca
Philippe Lhoste
Joined: 2010-09-02,
User offline. Last seen 42 years 45 weeks ago.
Re: Problems with scala package

On 09/09/2010 16:16, Amador Antonio Cuenca wrote:
> init:
> deps-jar:
> Compiling 1 source file to /media/ACUENCA/Labs/Test/build/classes
> No known dependencies. Compiling everything
> /media/ACUENCA/Labs/Test/src/Demo/Circuit/Test.scala:4: error: not found: type Bit
> def NOT(b: Bit): Bit = Bit(!b.getValue)

What is strange, is that it compiles only one source file, ie. apparently it doesn't
compile Bit.scala
Not sure why, I don't know NetBeans.

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