is this an evaluation bug, or do I miss something?
# announcements
m
is this an evaluation bug, or do I miss something?
I would expect the first line to resolve to
false
since all variables are -1 and the last evaluation tells me that it actually should be
false
s
Seems odd. This isnt javascript where runningEntryId is actually a string or something?
m
kotlin and they are Long.
s
Yeah but is it kotlin/js ?
m
sorry, no, its for Android
k
Looks like
it?.id ?: -1
expression resolves to the value of Int type when used as a part of a bigger expression
m
quickly verified.. (it?.id ?: -1L) works. this must be a compiler bug since
if (1L== 1)
will return a compiler error.
s
You can always submit it but there are limits to how far the compiler can go. I think what you have is basically:
1L == (-1 as Number)
which compiles also.
k
I think the question is more about the Elvis operator behavior, it is really misleading here. It would make sense to • either always infer
Any
type for the expression like
it?.id ?: -1
in case left-hand part is inferred to be other than
Int
- this would make this pitfall more visible (and btw if you replace
-1
with a reference to variable of
Int
type, the actual type inferred for the expression would really be
Any
) • or emit the run-time conversion of the right-hand numeric constant to
Long
into the generated bytecode.