1

as in title: Augment assignment and increment are not supported for local delegated properties ans inline properties - I get this for a following piece of code:

var timer by someDelegate { }
timer += someOtherValue

which compiled perfectly as long as half an hour ago. Cleaning the project and resetting Android Studio did not help.

Antek
  • 721
  • 1
  • 4
  • 27
  • you can try to replace it with `timer = timer + someOtherValue`. – holi-java Aug 08 '17 at 14:44
  • Providing more context of your problem. – Miha_x64 Aug 08 '17 at 14:46
  • I confirm it doesn't work for me ether – voddan Aug 08 '17 at 14:49
  • The should be ok because when `plusAssingned` is not defined, such an expression is converted to `timer = timer + someOtherValue – voddan Aug 08 '17 at 14:50
  • Please file a bug at https://youtrack.jetbrains.com/issues/KT – voddan Aug 08 '17 at 14:51
  • 1
    @voddan No. `plusAssingned` is for immutable variables if the `plus` exists. in other words, the `+=` will always use the `plus` with a mutable variable when both `plusAssingned` and `plus` are exist. you can see here as further: https://stackoverflow.com/questions/44558663/overloading-and-operators-for-number-classes/44562224#44562224 – holi-java Aug 08 '17 at 14:52
  • @holi-java of course this is what I did, thank you :) But still it bothers me, how it _just_ stopped working! – Antek Aug 08 '17 at 15:24
  • @Miha_x64 I define it in an extension function for my specific type of `activity` (a bit weird at first glance, but surprisingly very readable). Is it enough or do you need more information? – Antek Aug 08 '17 at 15:25
  • @holi-java regarding mentioned stack question, I will just look into the definition of the delegate I used – Antek Aug 08 '17 at 15:28

1 Answers1

1

This is because this feature is not implemented yet, it's not a bug, :). here is the source code of the StackValue#L1815 in Kotlin 1.1.3 as below:

if (stackValue instanceof Delegate) {
    //TODO need to support
    throwUnsupportedComplexOperation(((Delegate) stackValue).variableDescriptor);
}

Why does the property can working with +=, this is because the Delegate is wrapped by getter/setter, which means it is invisible from the client code.

holi-java
  • 29,655
  • 7
  • 72
  • 83
  • Ah yeah, we saw that, but I'm still wondering why _it just stopped working_ (it worked for a week or so) - or maybe, why it worked in the first place! – Antek Aug 08 '17 at 15:42
  • @Antek maybe you used the newest version kotlin in last week. – holi-java Aug 08 '17 at 15:43
  • how this could be? The version used in the project has been stable at 1.1.3-2 since 13th of July, and I don't remember any update notifications – Antek Aug 08 '17 at 15:45
  • @Antek I'm sure you can't, maybe you make it to a **property** rather than a local **variable**. the newest version kotlin also don't support that: https://github.com/JetBrains/kotlin/blob/master/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java#L1718 – holi-java Aug 08 '17 at 15:47
  • computers are weird (: – Antek Aug 08 '17 at 15:48
  • regarding property - I'm defining `timer` as a local variable inside extension function, I can make it an extension property. I hope I will have time to look into this possibility. – Antek Aug 09 '17 at 07:45