Skip to content

Roll your own Enum will not compile #7390

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

Closed
ekrich opened this issue Oct 8, 2019 · 2 comments
Closed

Roll your own Enum will not compile #7390

ekrich opened this issue Oct 8, 2019 · 2 comments

Comments

@ekrich
Copy link
Contributor

ekrich commented Oct 8, 2019

minimized code

import java.{lang => jl}

final class ConfigIncludeKind private (name: String, ordinal: Int)
    extends jl.Enum[ConfigIncludeKind](name, ordinal)

object ConfigIncludeKind {

  final val URL       = new ConfigIncludeKind("URL", 0)
  final val FILE      = new ConfigIncludeKind("FILE", 1)
  final val CLASSPATH = new ConfigIncludeKind("CLASSPATH", 2)
  final val HEURISTIC = new ConfigIncludeKind("HEURISTIC", 3)

  private[this] final val _values: Array[ConfigIncludeKind] =
    Array(URL, FILE, CLASSPATH, HEURISTIC)

  def values: Array[ConfigIncludeKind] = _values.clone()

  def valueOf(name: String): ConfigIncludeKind =
    _values.find(_.name == name).getOrElse {
      throw new IllegalArgumentException(
        "No enum const ConfigIncludeKind." + name)
    }
}

observation

[info] Compiling 1 Scala source to /Users/eric/workspace/dotty-cross/target/scala-0.19/classes ...
[error] -- Error: /Users/eric/workspace/dotty-cross/src/main/scala/Main.scala:70:39 ----
[error] 70 |    extends jl.Enum[ConfigIncludeKind](name, ordinal)
[error]    |                                       ^^^^
[error]    |    too many arguments for constructor Enum: (): Enum[ConfigIncludeKind]
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 2 s, completed Oct 8, 2019 9:17:30 AM

expectation

Should compile and work.

@smarter
Copy link
Member

smarter commented Oct 8, 2019

Duplicate of #7174

@smarter smarter marked this as a duplicate of #7174 Oct 8, 2019
@smarter smarter closed this as completed Oct 8, 2019
@ekrich
Copy link
Contributor Author

ekrich commented Oct 8, 2019

Sorry about that, I couldn't find it - was filtering with my user name - incorrectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants