Allow multi-line expression at infix operator boundary#35
Merged
Conversation
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
everdance
approved these changes
Jun 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allow multi-line expression at infix operator boundary
Note: Only open expressions are affected. Closed expressions are not affected, there is no question where they end.
Context
Semicolon omission in statement syntax leads to the problem of when an expression ends.
Languages like Go and JavaScript use heuristics to automatically insert
;at line ends.When things are not clear, users may add
;explicitly.Languages like Swift and Scala use heuristics to tell whether or not to continue a multi-line expression.
Jo's rule is closer to Swift: multi-line expressions only continue at infix operator boundaries. An operator is taken as infix if there is space to its lhs and no space to rhs.
What has changed
Previously, the following code is invalid:
The programmer has to use parentheses to wrap the expression as in Python.
With the current change, the code above is accepted. One condition:
Alternative 1
The separating infix operator rule allows the following code:
Arguably, no one will write the code above. They can indent
3to make things clear:We could add the requirement that the continued line must be indented. However, the price to pay is that the following code patterns become invalid:
Users have to write
We reject the design on the following two considerations.
First, the purpose of the PR is to reduce frictions for LLMs and new comers from other languages. The restriction goes against the goal.
Second, while a syntactic restriction can be justified by it rejecting unreadable code, it is a much weaker argument than rejecting error-prone code.
Alternative 2
Do nothing. The two common use cases for multi-line expressions are
Arithmetic expressions spanning multiple lines is less common and it's debatable whether it's a good style or not.
For both the two cases above, the existing colon syntax can better handle them:
The counter-argument is friendliness for LLMs and users from other languages.
Checklist
tests/pos/ortests/warn/How to sign off commits
Use
git commit -sto add theSigned-off-byline automatically:To add a sign-off to the last commit retroactively:
To add sign-off to the last 3 commits:
Security impact
No