Skip to content

fix(lint): format a glued < that no > closes instead of throwing - #2231

Merged
Lorenzobattistela merged 1 commit into
bendlang:mainfrom
rbmr:fix/lint-glued-angle
Nov 23, 2026
Merged

Lorenzobattistela merged 1 commit into
bendlang:mainfrom
rbmr:fix/lint-glued-angle

Conversation

@rbmr

@rbmr rbmr commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

format/layout throws on a file that checks when a < glued to a name is not a type argument. bend-lint then exits 2 and writes nothing, although the fix is marked safe:

import Base
def main() -> IO(Unit):
  do IO<Unit>:
    Unit<- IO.print("x")
    IO.print("y")
$ bun tools/bend-lint/src/lint.ts t.bend --rules tools/bend-lint/rules/format.ts --fix
bend-lint: format/layout: unbalanced delimiters
$ echo $?
2

(a<4 : U32) in a def body does the same. Removing the one space before <- in a repository file, such as line 92 of tests/base/read_bounds.bend, is enough to reach it.

Why

tokens() splits a <- glued after a name into < and -, so that Box<-T opens type arguments. tree() then opens a group at every < glued after a name. In Unit<- m and a<4 no > closes that group, so tree() throws at the end of the file.

What changes

  • tokens() splits <- only when no space follows it, as in Box<-T. Unit<- m stays a bind and formats as Unit <- m.
  • tree() gives a < group's tokens back to its enclosing group when a ), ], } or the end of the file comes before its >. (a<4 : U32) formats as (a < 4: U32), as (a < 4 : U32) already does.
  • A fully glued Unit<-m still splits. The rule's parse check now reports it without a fix instead of throwing.

Verified

Linux x86_64, Bun 1.4.0:

  • bun test rules/format.test.ts passes 40 tests. The new test fails on main with the thrown error.
  • --fix on every .bend under tests/, bench/ and demos/ (1,957 files) gives byte-identical files and exit codes with and without this change.
  • 106 layout variants of 32 repository files, each of which checks, threw on main. With this change each is formatted, still checks and prints what it printed before, and a second --fix changes nothing.

tokens() split every <- glued after a name, and tree() opened type
arguments at every < glued after a name, so x<- m and (a<4 : U32)
left a group open and format/layout threw 'unbalanced delimiters'.

<- is now split only when no space follows it (Box<-T), and a < group
that a closer or the end of the file reaches first gives its tokens
back to the enclosing group.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@Lorenzobattistela
Lorenzobattistela merged commit 358e684 into bendlang:main Nov 23, 2026
1 check passed
nicolas-abril added a commit to nicolas-abril/bend that referenced this pull request Nov 24, 2026
, bendlang#2224-bendlang#2226, bendlang#2231, bendlang#2285, bendlang#2286, bendlang#2288 and others)

One conflict, in emit_unfold: bendlang#2288 annotates an unfolded call's lets with
the argument types instantiated by the earlier arguments; bendlang#2162's deep unfold
keeps its arguments unannotated there and annotates them the same way after
folding (its type walk renamed D, beside bendlang#2288's T). Both kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants