i am observing there is a special tratement for c...
# announcements
t
i am observing there is a special tratement for class fields of type
Long
when they are initialized with
0
but i cannot find documentation for this behavior. furthermore it is not applied when the code is compiled in to javascript. any help on this?
c
probably because on the jvm primitives are used and those default to 0
so its an implementation detail and you better not depend on it especially in your cross platform project
t
i'd go a step further and consider it a bug. A test - even on jvm - might fail when you change a field's value from 0 to 1 although it doesn't depend on either of these values
what do you think?
d
Are you talking about a setter being called or not being called?
If the property is virtual or has a setter and the setter isn't invoked when initialized to 0 on the jvm, that would be a bug, but I think it's unlikely that it would only be discovered now.
t
no it does not have a setter nor is it virtual. I am pretty sure not calling
foo.var = 0
is on purpose on the jvm - but if it is, it shouldn't be called on different platforms either
it's the very same code with a different behavior on different palttforms
d
Well, there's some platform specific behaviour, which allows for an optimization on the jvm. Is that breaking something? Generated code is platform specific, what's the matter?
t
Well in my case the class was calling a super cosntructor which in turn initialized the child class (which is bad alread - yet for other reasons im aware of). now the already initialized fields were initialized again by the child's constructor overriding the values set through the parents ctor.
if the
Long
field is initialized with 0 this works on jvm but fails on js. If it's initialized with 1 it brekas on both platforms
d
Do you have a unit test that shows this?
t
i do. but will try to create a minimal example
d
So if I understand you correctly, the child constructor is assigning 0 to a property from a superclass, and the jvm compiler is not emitting instructions to do that?
That would be a bug, which could reasonably exist also.
t
give me a minute, i will shoud you code demonstrating it
👍🏻 1
this code works on jvm if, and only if in line 18 we initialize the
long
with
0
. if we initialize with
1
the test breaks
on js it will never work
d
What do you think the behaviour should be?
t
as mentioned before we could argue that line 11 is an error, yet it is allowed and could be usefull at least
i THINK the behavior should be consistent regardless of the initial value of
long
d
That's a good point.
You should report it on kotl.in/issue
t
i'll do, thank you 🙂