Not sure if something like this would be possible,...
# language-proposals
u
Not sure if something like this would be possible, but seems like possibly nice idea. Would let you only access foo within it's scope versus having to declare outside or reusing.
Copy code
if (val foo = someClass.someProperty == 1) {
            // can access foo here
        }
d
Your syntax is very hard to read. Intuitively
val foo = someClass.someProperty == 1
reads as
val foo = (someClass.someProperty == 1)
, not
(val foo = someClass.someProperty) == 1
(like
val
declaration in
when
) If you really don't want to intoduce
foo
to outer scope you can use some scope function
Copy code
someClass.someProperty.let { foo -> 
    if (foo == 1) { ... }
}
or just replace
if
with
when
Copy code
when (val foo = someClass.someProperty) {
    1 -> ...
}
u
Ah fair enough didn't think about it as assigning the condition, can see how that's easily misunderstood.