kool icon indicating copy to clipboard operation
kool copied to clipboard

Suggest KSL return make infix fun

Open andrey-zakharov opened this issue 3 years ago • 3 comments

https://github.com/fabmax/kool/blob/f7e6d2e9bc8f9b936a0f1f120d08af67c8b4ad43/kool-core/src/commonMain/kotlin/de/fabmax/kool/modules/ksl/lang/KslFunction.kt#L79

https://www.baeldung.com/kotlin/infix-functions

andrey-zakharov avatar Jul 07 '22 16:07 andrey-zakharov

As far as I know infix functions only work between two arguments, so, witrh an infix return, you would need to write something before it to work:

kslFunctionBody.apply {
    // this would not work because there is no argument left of return
    `return` someValue

    // this would work but is not better than the current non-infix variant
    kslFunctionBody `return` someValue
}

Am I missing something?

fabmax avatar Jul 08 '22 09:07 fabmax

According to https://kotlinlang.org/docs/functions.html#infix-notation

Infix functions must meet the following requirements:

So, as we have KslScopeBuilder.return and one argument returnValue it should works

andrey-zakharov avatar Jul 08 '22 12:07 andrey-zakharov

Yes you can declare it as an infix function, but it doesn't make a difference because you can't invoke it 'infix-style' as long as there is no argument left of it (like in my example above).

I mean I can make it infix, but it also won't make anything better (but it should not hurt either :smile:)

fabmax avatar Jul 08 '22 13:07 fabmax