| overriding vars | Paul Phillips | 20/03/12 11:16 | It was an interesting revelation that the inability to override vars is not in the spec and is in question. class A { class B extends A { That one doesn't compile unless I also disable another check of unknown origin: if (sym.isValue && !sym.isMethod || sym.hasAccessorFlag) { Then it does, and B and A have the clever arrangement where A can I am sure things break down somewhere with nontrivial examples This also works on first blush: class C { var w = 1 } leading to the expected class C extends scala.AnyRef { |
| Re: overriding vars | martin | 20/03/12 15:55 | Yes, I think all this will require a bit of archeology to get at the real reasons. Either way would be OK with me. We can disallow overriding of vars in the spec, or allow them in the compiler. But the fact that this is currently disallowed in the compiler indicates that there probably were some problems with it. Cheers - Martin -- |
| Re: [scala-language] overriding vars | Daniel Sobral | 20/03/12 16:00 | Arguments for: it makes the language seem more regular/predictable. I * Scala's vals are really a field plus a getter, with the guarantee "So I can override a var with a getter and a setter?" * No, you can't. "Why?" * Err... Likewise, I personally dislike not being able to override a val with a -- I travel to the future all the time. |
| Re: [scala-language] overriding vars | Kevin Wright | 20/03/12 18:01 | I can imagine all sorts of difficulty if you override a var with defs and then pass the resulting object to some framework that accesses the underlying field through reflection. Hibernate and co would be examples of this kind of trickery.
To be fair though, you also get into the same problem overriding a var with a var. Perhaps the right approach would be to outright forbid the overriding of any non-abstract var by any mechanism whatsoever.
Taking due care, of course, to ensure that such a restriction doesn't harm Java interop - especially our ability to inherit from existing Java classes. --
Kevin Wright mail: kevin...@scalatechnology.com gtalk / msn : kev.le...@gmail.com vibe / skype: kev.lee.wright steam: kev_lee_wright "My point today is that, if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger" ~ Dijkstra
|
| Re: [scala-language] overriding vars | Daniel Sobral | 20/03/12 18:17 | On Tue, Mar 20, 2012 at 22:01, Kevin Wright <kev.le...@gmail.com> wrote: I can imagine all sort of difficulty if you use a framework that |