Groups
Groups
Sign in
Groups
Groups
scala-user
Conversations
About
Send feedback
Help
Reassignment sugar fails when getter is defined in super-trait
21 views
Skip to first unread message
Hanns Holger Rutz
unread,
Aug 12, 2012, 5:40:20 PM
8/12/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala...@googlegroups.com
I have a read-only and mutable variant of a data structure:
trait Config {
def method: Int
}
trait ConfigBuilder extends Config {
def method_=( value: Int ) : Unit
}
now I was expecting that the following works:
def test( b: ConfigBuilder ) {
b.method += 33 // fails
}
... but it doesn't :
<console>:10: error: reassignment to val
b.method += 33
^
If I _restate_ the contents of Config:
trait ConfigBuilder extends Config {
def method: Int
def method_=( value: Int ) : Unit
}
... it does compile
def test( b: ConfigBuilder ) {
b.method += 33 // ok
}
this kind of sucks with a dozen configuration keys. Is this some oversight in scalac or is there a deeper reason by the reassignment possibility is not seen in the first case?
best, .h.h.
Reply all
Reply to author
Forward
0 new messages