https://scastie.scala-lang.org/vtB4qDpEQWKhpRfRKpmfTQ
trait Config {
def extension: String
}
trait ConfigBuilder extends Config {
override var extension: String
}
class ConfigBuilderImpl extends ConfigBuilder {
private var _ext = "cache"
private var _extSet = false
def extension: String = _ext
def extension_=(value: String): Unit = { // !
_extSet = true
_ext = value
}
}
illegal method name: extension_= may not start with `extension_`
It seems counter-intuitive that you can define a var extension but not implement a setter method.
PR https://github.com/lampepfl/dotty/pull/9836 should be updated to deal with this and block var extension
or should we allow extension_= if it overrides a method with setter flag?
I think it might end up more consistent if we disallow it altogether.
decision was made to forbid this
We could maybe try to use an _extension suffix instead of extension_ prefix for extension methods. At first glance it looks like it would have fewer conflicting names.
Would that require +_extension to be written as `+_extension` by the user in an explicit reference?
is there a reason no special characters such as $ are used, as happens for example in specialization, default values, etc. ?
I would assume because the expanded name is intended to be called by the user in some circumstances, as opposed to those other constructs that should not be called explicitly
Isn't it a bit too "strong" to disallow var extension? Since extension is a relatively common name, newcomers might find surprising that val extension is allowed but if we use var and if the variable is non-local then it's forbidden.
Most helpful comment
is there a reason no special characters such as
$are used, as happens for example in specialization, default values, etc. ?