-
Notifications
You must be signed in to change notification settings - Fork 21
Objects extending Enumerations have inaccessible #Value type #3134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Imported From: https://issues.scala-lang.org/browse/SI-3134?orig=1 |
@paulp said: val doesWork: Broken.type#Value = getZero[Broken.type](Broken) |
@Ichoran said: Also, the "invalid" resolution does not address the complaint that the generic applied to a singleton returned a type that I cannot refer to. It inferred something, just not anything that I could specify (see REPL output res0 and compare to res1). (I do not intend to start a debate, just clarify the original posting; if this matter requires further discussion, I'll pick it up on scala-debate or some other appropriate venue.) |
@paulp said:
Quite possibly. As singleton type inference had already been closed wontfix in #1208 and duplicate in others since, I figured why not cover the bases. You may be interested to know that if you use the right command line options, you can define the method as you desire. When or if dependent method types will appear for real I cannot say. And yes, mailing list would be a better place. % scala -Xexperimental
// def getZero[E <: Enumeration](enum: E): E#Value = enum.withName("zero")
def getZero[E <: Enumeration](enum: E): enum.Value = enum.withName("zero")
scala> BugTestCase.correctlyTyped
res0: BugTestCase.Broken.Value = zero
scala> BugTestCase.wronglyTyped
res1: BugTestCase.Broken.Value = null |
Type-safe generic methods operating on Enumerations and returning a Value need to have signatures of the form
since it is not possible to specify the type of a particular instance:
The former is arguably typesafe enough, but unfortunately there is a bug in the implementation of inner class types inside objects:
Note that the Workaround class/lazy val pair should be equivalent to a companion object, but there is no way to write the correct type signature for the companion object. Although type inference works correctly, the REPL reports:
This makes it necessary to use one's own singleton objects instead of the language-supported ones. Either Broken.type#Value should mean Broken$$#Value (where Broken$$ is the class of the singleton object), or Broken#Value should be valid syntax and mean that, or E#Value should be equivalent to Broken.Value.
The text was updated successfully, but these errors were encountered: