Skip to content

[Kotlin] Returning a lambda with multiline code creates syntax errors #656

@K1rakishou

Description

@K1rakishou

In our project we are using a quite unorthodox way to check whether experiments are enabled/disabled. We have a special class, let's name it ExperimentChecker, which has lots of different methods, from simple ones like isOn()/isOff() to some advanced ones.

Consider the following code:

class SomeClass(
    private val expChecker: ExpChecker
) {
    fun someFunc(): SomeValue {
        return expChecker.check(Experiments.ExpName) {
            off { 
               logger.log("off branch called")
               SomeValue.OldValue
            }
            on {
               logger.log("on branch called")
               SomeValue.NewValue
            }
        }
    }
}

If we try to match and remove one of the branches along with expChecker.check(Experiments.ExpName) invocation we will end up with the following code (let's remove the off branch in this example):

class SomeClass(
    private val expChecker: ExpChecker
) {
    fun someFunc(): SomeValue {
        return logger.log("on branch")
               SomeValue.NewValue
    }
}

As you can see it introduces a syntax error which then crashes piranha.

I'm not sure if this is even supported by piranha. If it's not then we will have to figure it out on our own. But if it is supported then please could you point me to an example on how it should be handled? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions