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
explicit case class companion does not extend Function / override toString #3664
Comments
Imported From: https://issues.scala-lang.org/browse/SI-3664?orig=1 |
@milessabin said: |
@lrytz said: |
Fred (fred) said: This one is annoying for me when trying to use the new "JSON Inception" coming in playframework 2.1 (http://mandubian.com/2012/11/11/JSON-inception/). Consider this using play 2.1-RC1 and scala 2.10.0-RC1:
|
@hseeberger said: |
Jeff May (jeffmay) said: I notice that a lot of people I work with don't really know the difference between |
Stephen Compall (s11001001) said: |
Jeff May (jeffmay) said: My issue with this is that it is inconsistent. I wouldn't mind typing the work around of using the apply method every time. The fact that the rules change for what seems like an unrelated change is what bothers me. |
Sven Ludwig (sourcekick) said: It would be cool to see this fixed for a better "just works out-of-the-box" feeling. |
hi all, yet another case. this is a fundamental mistake, no? we either shouldn't inherit |
@HuStmpHrrr It's hard to say. It's inconsistent, and a frequent gotcha, but the obvious solutions have problems. Never extend function type: Well, this is just piling on the inconvenience. Thanks but no thanks. Extend function type even when explicitly defining case class Foo(b: Bar)
object Foo extends (Baz => Foo) {
def apply(bz: Baz): Foo = apply(bazToBar(bz))
} This is a direct example, but you might also be extending the function type indirectly, via extending some other trait you wish your It just so happens that, in the absence of any syntax saying you don't want the function extend, the syntax for saying so is to declare the |
One proposal to signal |
so JsonError can be used instead of JsonError.apply
* Extract ErrorOps, use liftErr instead of leftMap JSON error formatting cleanup CHANGELOG_BEGIN CHANGELOG_END * Good we have tests for this stuff * Apply scala/bug#3664 work-around, so JsonError can be used instead of JsonError.apply * error formatting
I just ran into this by attempting to use case class Person(name: String, age: Int)
val p = ("Abe", 42) Calling: Would really love to see this fixed. |
wow this issue is still open. one potential fix I can come up with is to add a piece of syntax so that intention is revealed properly. for example, case class Person(name: String, age: Int)
object Person {
// something
} this creates a imagine the syntax is augmented: case class Person(name: String, age: Int)
extend object Person {
// something
} in this imaginary case, the in general, the fact that we are not able to add additional functionality to companion objects is quite absurd imo. |
But you can. Everything that you write in the body of The weird thing is this:
The |
I guess @hmemcpy just mentioned that there is a good reason to believe these two functions are special too. in any case, it's always good to have syntax to distinguish intentions, otherwise once it's "fixed", someone else is going to complain. |
Folks were still commenting here a year after the matter was settled at lampepfl/dotty#6190. Note that the companion extended It would be or have been nice to balk only at mixing in traits where it is expensive, imposing the parent class where feasible. The dotty solution includes eta-expanding |
When explicitly defining the companion object of a case class, the compiler does not add a
FunctionN
parent and does not overridetoString
.working as expected:
unexpected:
The text was updated successfully, but these errors were encountered: