Why in this example `item1` is highlighted with "C...
# announcements
t
Why in this example
item1
is highlighted with "Cannot infer a type for this parameter. Please specify it explicitly"? Is there a way to modify
someWrapper()
to remove this error?
s
it should be
item
instead of
item1
, but aside from that, intuitively this should work... weird.
m
I guess
{ item1 -> println(item) }.someWrapper()
is evaluated first and then it's not clear what the lambda is supposed to take or return. Because that's unknown
.someWrapper()
should also not resolve, but that's probably not indicated because it's a subsequent error, not the initial one. Would
item
(item1) have a type then the result of the lambda can be inferred as
Unit
(from
println
with known parameter type) and then
.someWrapper()
should also work fine. That everything is put into
addReceiver
in the end is probably not considered because that would require that the expression is evaluated in the completely opposite order (outside to inside).
t
mm, if I add wrong type to
item1
- then IDE highlights
.someWrapper()
with wrong "type inference failed" error
So I guess @Marc Knaup is right