Scala plugin and package objects: good code is red
I am encountering an issue where some elements of a package object are resolved and others are not.
In an attempt to better characterize the weirdness, I created a mashup of greatest hits from various package objects, some of which work without a hitch and others of which cause Idea to complain.
Declaration of package object
package com.test.whatever
package object foo {
val Stats = com.twitter.ostrich.Stats
type Counter = com.twitter.ostrich.Counter
type Histogram = com.twitter.ostrich.Histogram
val SOME_CONSTANT = "constant"
object FooEnum extends Enumeration("F", "B", "B2") {
val Foo, Bar, Baz = Value
}
sealed abstract class FooType {
val description: String
}
case object BoatAnchorType extends FooType {
val description = "BoatAnchor"
}
implicit def someThingy(x: String): Option[String] = { //stuff }
class FooError(msg: String = "Oh no!") extends Error("FooError: "+msg)
object FooBar {
// stuff
}
}
Attempt to use package object
package com.test.whatever2
import com.test.whatever.foo_
object WhateverThing {
def doStuff(): Unit = {
println(SOME_CONSTANT) // works!
println(FooEnum.Foo) // works!
val thingy: Option[String] = "meh" // Idea doesn't complain here, ? although I don't think it would anyway
val fooType: FooType = BoatAnchorType // works!
Stats.timing("big ugly hack") { // does not work - Idea offers to import com.twitter.ostrich
// codeblock
}
// same story for Counter, Histogram
FooBar.someMethod() // just red, Idea offers to import com.test.whatever.foo.FooBar and stays red even if you do
throw new FooError("How did I get here?") // works!
}
}
Despite the red highlights and import offers, the code compiles without complaint in sbt. I am currently using 0.3.2093 with Maia (I update to latest nightly build every morning).
Could you please let me know if improvements to the Scala plugin's package object support are in the works? Thanks.
Please sign in to leave a comment.
I have IDEA 10.0.1 Ultimate with the Scala plugin and noticed the same problem.
In the package object, IDEA doesn't see the classes that are defined in the package in other source files.
It's a bug in the Scala plugin which has unfortunately not yet been fixed...