eirikb
07/13/2021, 5:25 AMASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
upon assignment only. While that warning is technically correct, and makes sense, it would be nice to remove it. How?
My code looks like this:
var ok by okProp
ok = true
where setting ok
will have side effect. Example: https://pl.kotl.in/81eXfsXLG (press run to get the warnings).
On a side note, the decompiled code looks like this:
KProperty var1 = $$delegatedProperties[0];
ReadWriteProperty ok = okProp;
ok.setValue((Object)null, var1, true);
As one would expect the variable will be both accessed and assigned, just not in KotlinDave K
07/13/2021, 6:08 AMok
is instantiated but never used.
Adding
if (ok) println(“ok”)
Makes the warning go away
And the same warnings appear with
var t: Boolean
t = true
I think also if you return
ok from some function it would similarly not provide the warning. Essentially you’re instantiating this variable without any purpose?eirikb
07/13/2021, 6:09 AMby
is used only to trigger itDave K
07/13/2021, 6:17 AMeirikb
07/13/2021, 6:25 AMDave K
07/13/2021, 6:31 AMeirikb
07/13/2021, 6:36 AMeygraber
07/13/2021, 6:47 AMval commonMain by getting
With commonMain
not being used after the declarationeirikb
07/13/2021, 6:54 AMeygraber
07/13/2021, 3:22 PMeirikb
07/14/2021, 4:43 AMjs
under kotlin
. I could safely remove val jsMain by getting
. But yes it could have side effects, very similar to my case