-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Kotlin] Returning a lambda with multiline code creates syntax errors #656
Comments
is the expected code (we want to retain the braces right?)
I am assuming you wrote a feature flag api cleanup rule specifically for your custom API, which produced the above change, where the |
Sorry forgot to mention what it's expected to look like:
Basically the code is extracted from the But it doesn't work because of return. It will also probably not work if the result of that expression were to be assigned to a variable and probably many other cases that I can't think of right now.
Yes, we wrote a custom rule. Here is the full rule.
And then in For now, my idea to fix this is to wrap multi line code into a Kotlin's
Not sure how to do this right now, just an idea in case there is no simple solution. |
sorry! This issue completely slipped off my mind.
|
is ur codebase open source? |
No, it's not open-source. So the above query removes everything except for the lambda body now. So instead of this code:
It now produces this code:
Which might work in some languages, but not in Kotlin, because in Kotlin this block:
basically means
But I don't know how to insert new text into the code using piranha rules. Is this possible? If that is possible then I can figure out the rest. |
yes inserting text is possible as an "update" operation.
or
Either shud be possible u can update ur replace to |
Yes, this works. Thank you very much! |
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 likeisOn()
/isOff()
to some advanced ones.Consider the following code:
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):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.
The text was updated successfully, but these errors were encountered: