Using `b: Int? by p.invoke()` is working :confused...
# random
d
Using
b: Int? by p.invoke()
is working 😕
k
Is it only in the IDE or only in the actual build? Then either new type inference is helping you or its a regression.
d
I’m on 1.3.41, but I already noticed it in the past. It’s happening only at compile time, no error in the IDE
k
Right, then your problem is fixed in the new type inference and you just need to wait for it to be fully released.
l
Or just enable new type inference. First Google result should help.
👍 1
d
Oh, thanks, didn’t read that carefully, I tough it was already enabled. Is there a way to test it? Anyway AFAIR the IDE was ok also in older versions, but perhaps I’m wrong on that
k
That's the point, it's already enabled in the IDE. We're all testing it.
d
Seems that the result is the same with the NewInference 😕
l
Then you should report it on kotl.in/issue
d
I’m trying to repro on play.kotlin
d
There are definitely some limitations on what kind of type inference the compiler does. Your two examples are different in that in the second case it is trying to infer the return type of the method based on the variable it's assigned to (this is a tricky case). In the first case it's just inferring the type of the assigned variable based on the return type of the method, which you're explicitly specifying. It is weird the syntax change (
p()
vs.
p.invoke()
) makes a difference though.
d
Example here. Replace
invoke
with direct function call on
var nullable
d
Yeah, to me this is the bug (based on your example code):
Copy code
var nullableWorking: Int? by Scope<Int?>()
var nullableWorkingTwo: Int? by Scope.invoke()
var nullableFailing: Int? by Scope()
Specifically the fact the second line works and the third line fails is unexpected.
d
So I guess it should be reported 🙂
👍 1
l
You did? If so, please link it 🙂
d
Please suggest me if I should add more details
d
I might include a minimum reproducible snippet in the ticket. Also you can remove some lines from the minimum sample.
d
I don't think I could remove something 🤔
d
Since my goal is to have whoever is working on the ticket to be able to quickly identify the issue with just the ticket.
d
Yes, I'll add a snippet as soon I'll be on pc, thanks about that
updated