It's been mentioned before ( Topic 1546, Topic 1921 ) and I find I keep coming back to it... being able to define (synthetic) fields for const mixins:
const mixin Serv {
abstract const Str dude
}
const class MyServ : Serv {
override const Str dude {
get { "stuff" }
set { .. do stuff .. }
}
}
As no state is being held, and the compiler has already calculated the field is synthetic, it should really be allowed.
I could have get() and set() methods, but they're ugly and look disjointed. What I really want to have is:
serv := MyServ()
serv.dude = "sweet"
var := serv.dude
Interestingly, const mixins are allowed @Operators, so I can already give more complicated map and addition behaviour to my const classes!
If synthetic fields are too tricky, I could suggest extending @Operators for basic get n set methods, but that's quite nasty and I don't think anyone wants that!
EDIT: Ah - ignore my rant above, I just found Ticket 2110.
brianFri 2 Aug 2013
If its const you don't need the setter, so you can just make a method:
Yeah there should probably be a compiler error there, sort of an interesting edge case. But I'm still not sure why you are trying to make it a field in the mixin versus a method like a suggested. By definition if its const, then the mixin never needs a setter.
SlimerDudeTue 6 Aug 2013
Simple - I have a const class with a synthetic getter / setter (where the field value is calculated / held elsewhere) and I wish to expose it through a mixin.
See BedSheet's HttpResponse.statusCode for an example. (Yeah, I was quick to jump on this! I was quite excited by it!)
brianTue 6 Aug 2013
Promoted to ticket #2177 and assigned to brian
Ok, that makes sense. Probably won't fix it quickly, but definitely worth tracking
SlimerDude Fri 2 Aug 2013
It's been mentioned before ( Topic 1546, Topic 1921 ) and I find I keep coming back to it... being able to define (synthetic) fields for const mixins:
As no state is being held, and the compiler has already calculated the field is synthetic, it should really be allowed.
I could have get() and set() methods, but they're ugly and look disjointed. What I really want to have is:
Interestingly,
const mixins
are allowed@Operators
, so I can already give more complicated map and addition behaviour to my const classes!If synthetic fields are too tricky, I could suggest extending
@Operators
for basic getn
set methods, but that's quite nasty and I don't think anyone wants that!brian Fri 2 Aug 2013
If its const you don't need the setter, so you can just make a method:
SlimerDude Fri 2 Aug 2013
Fat finger syndrome - I posted the comment mid-flow... I've just found Ticket 2110 anyway, so err, ignore!
SlimerDude Fri 2 Aug 2013
Stop the press! You can!
It's counter intuitive, but the trick is to NOT declare the field as const:
I'm happy it works, but err Brian, is this behaviour expected?
SlimerDude Fri 2 Aug 2013
Readonly const fields still aren't possible but it does give rise to this interesting edge case Err:
gives an Err at runtime:
brian Tue 6 Aug 2013
Yeah there should probably be a compiler error there, sort of an interesting edge case. But I'm still not sure why you are trying to make it a field in the mixin versus a method like a suggested. By definition if its const, then the mixin never needs a setter.
SlimerDude Tue 6 Aug 2013
Simple - I have a const class with a synthetic getter / setter (where the field value is calculated / held elsewhere) and I wish to expose it through a mixin.
See BedSheet's HttpResponse.statusCode for an example. (Yeah, I was quick to jump on this! I was quite excited by it!)
brian Tue 6 Aug 2013
Promoted to ticket #2177 and assigned to brian
Ok, that makes sense. Probably won't fix it quickly, but definitely worth tracking