Skip to content

[flutter_tools] Use JSON_INPUT COMPILE_EXPRESSION for expression evaluation - #190722

Merged
auto-submit[bot] merged 1 commit into
flutter:masterfrom
bkonyi:issue-55731
Aug 10, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:masterfrom
bkonyi:issue-55731

Conversation

@bkonyi

@bkonyi bkonyi commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Description

When evaluating expressions in Flutter debug sessions, DefaultResidentCompiler._compileExpression was communicating with frontend_server using the legacy line-delimited protocol (compile-expression <boundaryKey>). Because frontend_server's state machine transitions out of expression parsing upon receiving the first newline character, multi-line expressions had only their first line evaluated, with subsequent lines misread as variable definitions.

This PR updates DefaultResidentCompiler._compileExpression in packages/flutter_tools/lib/src/compile.dart to use the structured JSON_INPUT protocol with 'type': 'COMPILE_EXPRESSION' (mirroring COMPILE_EXPRESSION_JS in _compileExpressionToJs), safely encoding multi-line expressions and scope definitions into a single JSON payload.

Fixes

Fixes #55731

Pre-launch Checklist

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 7, 2026
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Aug 7, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors DefaultResidentCompiler.compileExpression to send expression compilation requests as JSON-encoded payloads under the JSON_INPUT protocol instead of multi-line plain text. It also updates and adds corresponding unit tests. Feedback suggests closing the newly introduced StreamController instances in tests to prevent resource leaks, and parsing the output JSON in tests rather than comparing raw strings to improve test robustness.

…uation

Use the structured JSON_INPUT protocol with the COMPILE_EXPRESSION
command type when compiling expressions for the Dart VM in
DefaultResidentCompiler.

Previously, flutter_tools used the legacy newline-delimited command format
(compile-expression <boundaryKey>). Because frontend_server transitions
out of the expression-reading state on the first newline, any multi-line
expression had only its first line evaluated, with subsequent lines
misinterpreted as variable definitions.

Using the JSON_INPUT protocol safely preserves newlines and complex
expressions across stdin IPC.

Fixes flutter#55731

@chingjun chingjun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I happen to be looking at a compile-expression issue the other day. This would make it so much easier!

@bkonyi

bkonyi commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

I happen to be looking at a compile-expression issue the other day. This would make it so much easier!

I had no idea this was even a legacy format and that we had a JSON-based replacement until I came across this! It's much nicer! 🥳

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 10, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Aug 10, 2026
Merged via the queue into flutter:master with commit eed6f4b Aug 10, 2026
22 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Debugger expression evaluation only considers first line of multiline expressions for Flutter

2 participants