#1546 Const and abstract

dsav Wed 25 May 2011

Why it's not possible to define a const abstract field? E.g. something like this:

mixin Test1 {
  abstract const Int tmp

We can define tmp as a method, but this doesn't provide insurance that value returned by tmp() won't change.

P.S. I know that mixin itself can be constant. But it's not what I want.

brian Wed 25 May 2011

Its an interesting proposal. As you said you could just specify a method and state in docs that it should be const as part of the method contract. Although we could actually enhance the language to allow the compiler to enforce it. Its a bit more complication in the language and compiler, but gives you a bit more static enforcement. Personally I'm sort of the fence. I like it, but also always hate adding anything that doesn't really add value. Other comments?

Login or Signup to reply.