Skip to content

fix(import): the path error says each name starts with a letter or _ - #1964

Merged
Lorenzobattistela merged 6 commits into
bendlang:mainfrom
sebastianbreguel:fix/import-path-message
Nov 2, 2026
Merged

Lorenzobattistela merged 6 commits into
bendlang:mainfrom
sebastianbreguel:fix/import-path-message

Conversation

@sebastianbreguel

@sebastianbreguel sebastianbreguel commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1961.

An import is refused at two points, and both used one message: "an import path of plain names (letters, digits, _ and -; the hub's files import the hub's)". It named neither of the two rules behind it.

  • The path as written must be plain names, each starting with a letter or _ ([A-Za-z_][\w-]*), so no name segment starts with a digit and every key has one spelling (A name is words joined by dots, a namespace is the file's real path, a C id is unique, and every clash is refused #1042). import sub/2d/main.bend failed here with a message that listed the digit as allowed.
  • The file it resolves to must keep that shape too, and it must stay on its side of the hub: a hub file imports only hub files, and a local path does not land in the hub's store. Here every segment can be a plain name, so the name message sent the reader looking for a bad name that isn't there. And observed showed the path as written, even when the resolved path was the problem, as with a link to 2d/.

Change: the rules don't change, and neither does what they refuse. The new hub check takes two cases out of the old condition: a file in the store without a 0x head, and a hub file that reaches outside the store. Everything else the old condition refused keeps the name message.

  • bend2/bend.ts: a shape failure says "an import path of plain names (each starts with a letter or _, then letters, digits, _ and -)". When the resolved file fails it, observed is the resolved path. A hub crossing says "an import on its side of the hub (a hub file imports only hub files, and a local path stays out of the hub's store)", with the path as written.
  • guide/GUIDE.md: the imports paragraph states the name rule (7976 → 7980 ttok, cap 8000).
  • tests/import/digit_segment.bend (new): ./2d/x.bend gets the name message.
  • gates/ping.ts: two checks for the hub message. A file in the store imports ../stray.bend (the store's root) or ../../out.bend (outside it). A test under tests/ can't place files in the store, and ping already runs bend with its own HOME.
  • tests/import/{dotted_path,hub_head_path,hub_head_local,tilde_path}.bend: their #| lines carry the name message.
Import Before After
./2d/x.bend plain names (letters, digits, _ and -; the hub's …) plain names (each starts with a letter or _, …), observed './2d/x.bend'
./good/x.bend, good a link to 2d same, observed './good/x.bend' plain names, observed '2d/x.bend'
a store file importing ../stray.bend plain names (…) its side of the hub, observed '../stray.bend'
a store file importing ../../out.bend plain names (…) its side of the hub, observed '../../out.bend'
./d2/x.bend; a store file importing ./inner.bend runs runs

Verification (macOS arm64, Bun 1.4.2, Apple clang 21; Linux arm64 in Docker, Debian 13, Bun 1.4.2, clang 19 with X11 and ALSA headers)

  • The table above on macOS and Linux, with a temp BEND_LIB for the store cases.
  • The new ping block, run on its own (a copy of it, byte for byte, with bun bend2/main.ts in place of the installed bend and the same temp HOME): 0/2 on main, 2/2 with the change, on macOS and Linux.
  • Local replica of gates/test.ts on all tests, base 9d514f3 vs this branch, macOS and Linux: each test interpreted, built with -o t.js -o t, and the JS and the binary run under the gate's 5 s alarm. The only lanes that change are the four updated tests' message line, plus the new test. Against the #| lines: macOS interp 1782/1782, JS 927/927, C 875/878; Linux interp 1779/1782, JS 923/927, C 874/878. The misses are the same on the base: windows with no display, and stack_fault_trap's exit code on macOS.
  • gates/repo.ts: 54/54 (bend.ts 44,567 / 48,000 ttok; GUIDE.md 7,980 / 8,000)
  • gates/ping.ts as a whole: it needs the site repo, which is private
  • gates/test.ts on the minis
  • Metal, CUDA: the change is in the loader, before any backend

@Lorenzobattistela Lorenzobattistela self-assigned this Oct 30, 2026
@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Thanks, the new wording fixes the #1961 repro: sub/2d now names the rule, and sub/d2 still prints 1. All gates pass merged onto main 3c8fb66: repo 54/54, test 1785/1785, ping 81/81, perf 124/124, safe 0 false rejects.

One problem before merge: bad() is raised in two places, and the new wording only fits the first.

  • bend.ts:1003 checks the path as written. "each starts with a letter or _" is the right message there.
  • bend.ts:1011 checks the file the path resolves to. It also fails when the import crosses the hub boundary: a hub file importing a local path (hub(ns) && !got.startsWith(lib)), or a local import that resolves into BEND_LIB. In those cases every segment can be a valid name, so the new message sends the reader looking for a bad name that isn't there. It's also raised when a valid-looking path resolves (through a symlink, say) to a digit-led directory, and observed then shows the unresolved path, which looks fine.

Please split the two: keep the name message for the shape checks, and give the hub-boundary case its own message (that is what the "the hub's files import the hub's" clause was trying to say). If the shape check fails on the resolved path, show that path in observed. Then the name message can drop the hub clause.

Please also add a test for each message: a segment that starts with a digit (e.g. ./2d/x.bend), and a hub-boundary import that hits the new message. The four updated tests reject ., ~ and hub heads, and none covers either case.

@sebastianbreguel

Copy link
Copy Markdown
Contributor Author

Split as you asked. The shape checks keep the name message, now without the hub clause. The hub crossing gets its own: "an import on its side of the hub (a hub file imports only hub files, and a local path stays out of the hub's store)". Together the two checks refuse exactly what the old one did.

When the resolved file breaks the name rule, observed now shows the resolved path. For example, ./good/x.bend, with good a link to 2d, reports '2d/x.bend' instead of './good/x.bend'.

Tests: tests/import/digit_segment.bend covers the name message. A test under tests/ can't put files in the store, so the hub message can't be tested there. I added two checks to gates/ping.ts instead, since it already runs bend with its own HOME: one store file imports ../stray.bend, and another imports ../../out.bend.

One gap: I couldn't run ping as a whole, because it needs the private site repo. I ran the new block on its own, with the source CLI and the same temp HOME. It gives 0/2 on main and 2/2 with this change, on macOS and Linux. If the hub test belongs somewhere else, tell me where and I'll move it.

@sebastianbreguel

Copy link
Copy Markdown
Contributor Author

The red repo-gate is bend2/comp.ts: 66010 > 66000 ttok; this PR doesn't touch comp.ts, so it comes from main at merge time.

Lorenzobattistela and others added 2 commits November 2, 2026 07:02
…hs; GUIDE fits its cap

The error now names the import as written and where it resolves, relative
to the importing file: './link.bend' (resolves to '../2d/x.bend'), not a
path relative to the entry file with .bend appended. The hub-edge check in
gates/ping.ts is dropped (gate changes go through Taelin). GUIDE's imports
sentence is 3 ttok shorter, so it fits the 8,000 cap on current main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Lorenzobattistela
Lorenzobattistela merged commit 00d29f4 into bendlang:main Nov 2, 2026
1 check passed
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.

import: a segment starting with a digit is refused, but the error says digits are allowed

2 participants