2

In an Java Project this is possible while debugging by “mis”-using a conditional breakpoint to set a value to a property or variable:

Java Breakpoint

Unfortunately the same thing is not possible in a Kotlin Project. The error is: Assignments are not expressions, and only expressions are allowed in this context:

Kotlin Breakpoint

I know that I can do it in debugger window using “Set Value”, but then i have to do it every time manually. Using a conditional breakpoint/watchpoint the value is set automatically without even suspending the program until I delete the breakpoint. This is pretty useful for smoke test or presentations.

Thanks in advance!

2 Answers 2

2

Do not do that in the condition field, use "evaluate and log" - this breakpoint action is created specifically for this.

Also you can unset "suspend" and it will silently set value for you:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

You could execute a function to set the value:

run { text = "Some Value" }

This is an expression; it returns Unit, but has the side effect of setting your variable.

If the condition field needs you to return a boolean you can add it after:

run { text = "Some Value"; false }

This returns false so the execution wouldn't stop.

2 Comments

I thought about the same solution and tried it. It executes but sadly it does not change the value.
That's a bummer. It works for the evaluate expression panel. But I'm not exactly sure how this would be possible then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.