https://kotlinlang.org logo
#random
Title
d

Davide Giuseppe Farella

08/06/2019, 4:26 PM
Using
b: Int? by p.invoke()
is working 😕
k

karelpeeters

08/06/2019, 4:33 PM
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

Davide Giuseppe Farella

08/06/2019, 4:35 PM
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

karelpeeters

08/06/2019, 4:36 PM
Right, then your problem is fixed in the new type inference and you just need to wait for it to be fully released.
l

louiscad

08/06/2019, 4:38 PM
Or just enable new type inference. First Google result should help.
👍 1
d

Davide Giuseppe Farella

08/06/2019, 4:38 PM
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

karelpeeters

08/06/2019, 4:40 PM
That's the point, it's already enabled in the IDE. We're all testing it.
d

Davide Giuseppe Farella

08/06/2019, 4:46 PM
Seems that the result is the same with the NewInference 😕
l

louiscad

08/06/2019, 4:53 PM
Then you should report it on kotl.in/issue
d

Davide Giuseppe Farella

08/06/2019, 4:53 PM
I’m trying to repro on play.kotlin
d

dalexander

08/06/2019, 4:57 PM
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

Davide Giuseppe Farella

08/06/2019, 5:02 PM
Example here. Replace
invoke
with direct function call on
var nullable
d

dalexander

08/06/2019, 5:09 PM
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

Davide Giuseppe Farella

08/06/2019, 5:11 PM
So I guess it should be reported 🙂
👍 1
l

louiscad

08/06/2019, 5:34 PM
You did? If so, please link it 🙂
d

Davide Giuseppe Farella

08/06/2019, 7:10 PM
Please suggest me if I should add more details
d

dalexander

08/06/2019, 7:15 PM
I might include a minimum reproducible snippet in the ticket. Also you can remove some lines from the minimum sample.
d

Davide Giuseppe Farella

08/06/2019, 7:16 PM
I don't think I could remove something 🤔
d

dalexander

08/06/2019, 7:16 PM
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

Davide Giuseppe Farella

08/06/2019, 7:17 PM
Yes, I'll add a snippet as soon I'll be on pc, thanks about that
updated
2 Views