I Have the following code: (src/main/scala/coins/coins.scala)
object Main extends App {
def countChange(money: Int, coins: List[Int]): Int = {
[...]
And I'm trying to reference it from a test like this: (src/test/scala/coins/CoinsSuite.scala)
package coins
import org.scalatest.FunSuite
class CoinsSuite extends FunSuite {
import Main.countChange
test("only onw way to pay $0") {
[...]
And I get the following error:
not found: value Main [error] import Main.countChange
But on the other hand, from an sbt console it works fine
If I declare any package in the main file, like
package x
object Main extends App {
Console.println("Hello World!")
Then I can correcly issue import x.Main.countChange
Is there limitation on root package or on singleton objects visibility that I'm not aware of?
-- added
just to complete the answer, a couple of useful links at SO
https://stackoverflow.com/a/2030159/47633
https://stackoverflow.com/a/9822212/47633
https://stackoverflow.com/a/9822227/47633
Java (and Scala according to the same convention) is grumpy about importing things in the unnamed package, which is not the same thing as the root package. Put Main
into a package.
See Why is my object not a member of package <root> if it's in a separate source file?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With