You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An imported forward dotted datatype is resolved as lib.lib:Type #1514
lib.bend checks by itself, but importing it fails even though Fam is unused:
SOME PROOFS FAIL
Error:
- message : a declared datatype (unknown: lib.lib:Cell.At)
Context:
- p : Nat
Location: Fam
5 | case 0n: Unit
6>| case 1n+p: Cell.At<p>
| ^^^^^^^^^
7 |
Moving type Cell.At above Fam, or renaming it to an undotted CellAt, makes the imported file check. This also reproduces by importing the existing passing tests/check/mutual_type_def.bend, where Vec.Con<p> becomes tests/check/mutual_type_def.tests/check/mutual_type_def:Vec.Con.
The <..> parser appears to resolve the family head twice. parse_var first turns Cell.At into the internal key lib:Cell.At; because the datatype is declared later, the <..> branch then passes that key to parse_reso again and gets lib:lib:Cell.At. Forward datatypes are available during validation, but the malformed key is already stored in the parsed term.
Reproduced on current main at d71f42ee287bd7b9f86b44df44b210ac5eb651bd. I could not turn this into an Empty inhabitant: legal declarations cannot create the two-colon internal key, so this fails closed as an import/order bug.
Confirmed on main at 0e14aa8. Your diagnosis is right, and the same double resolution breaks a second shape: a \{..} arm that names a dotted constructor declared later.
bend2/bend.ts is human-written (AGENTS.md), so here is a patch and a test for a maintainer to apply, not a PR.
Cause
parse_var resolves a dotted name once and returns a Ref that holds the key (lib:Cell.At). Three call sites pass a Ref's key to parse_reso again:
When the name is already in the book, parse_reso returns the key unchanged. For a forward name in an imported file, parse_qual adds the namespace a second time.
A source name has no :, since char_is_name allows only letters, digits, _ and .. So a key that contains : is already resolved, and parse_reso can return it unchanged:
export function parse_reso(p: Parse, k: Name): Name {
+ if (k.includes(":")) {+ return k;+ }
const dot = k.indexOf(".");
Fixing only L2108 (out.$ === "Ref" ? out.k : parse_reso(p, out.k)) clears the family head. The arm still fails:
- expected : a constructor of forward_dotted_lib.Cell.At (missing, or already matched)
- observed : \{forward_dotted_lib: (v => v)}
The patch also covers L2137. For a forward T.add used in an imported file's (x + y : T), the import gave a different error (a defined name, observed ops). It now gives the same error the entry file does: that the method is used before it is defined.
Test
These go in tests/import/. On main, forward_dotted.bend fails with unknown: forward_dotted_lib.forward_dotted_lib:Cell.At. With the patch it prints 5.
forward_dotted_lib.bend:
# a def names a dotted datatype and constructor declared below it. an# imported file resolved Cell.At<p>'s head and the Cell.Mk arm's name# twice, into lib:lib:Cell.At, a key no file declares (#1514)importBasedefFam(n: Nat) ->Data:
matchn:
case0n:
Unitcase1n+p:
Cell.At<p>defget(p: Nat, c: Fam(1n+p)) ->U32:
{\{Cell.Mk: v=>v} : Cell.At<p>->U32}(c)
type Cell.At<-p: Nat>isData:
Cell.Mk{v: U32}
defmain() ->U32:
get(2n, Cell.Mk{7})
#|7
forward_dotted.bend:
# a module's defs name its dotted datatypes before declaring themimportBaseimport ./forward_dotted_lib.bendasLdefmain() ->U32:
L.get(3n, L.Cell.Mk{5})
#|5
With the patch, importing tests/check/mutual_type_def.bend also checks and prints 6.
What I ran
Tests:gates/test.ts's shard script, run locally on this Mac in 4 shards with the patch and the two tests, passes 1606 / 1608. The two failures are gfx_clicks and gfx_window. They expect "no display", but this Mac has a desktop session, so a window opens. main fails the same two here.
Hi @jasisz, I'd like to contribute to this issue. I reviewed the discussion and the proposed fix for the double resolution of imported forward dotted datatype names. Could you please assign this issue to me if it's still available? I'd like to work on the fix and add the necessary regression tests. Thank you!
@viridale PRs that change bend.ts are fine when a person writes them; the “do not edit it” line is in AGENTS.md and is addressed to coding agents. Contributor commits to that file land regularly. Since the patch and both tests are already done, I suggest you open the PR yourself. It’s a cleaner credit trail than a maintainer lifting it from the thread.
@AbarnaaSree this repo doesn’t hand out issues, so there’s no assignment to wait for. Those few assignees you’ve seen are the maintainers themselves. Whoever opens the PR has it! Since this one is already written up by @viridale, maybe it's better to proceed with another open issue.
@viridaleheads-up: #1585 fixes the <..> head site but not the \{..} arm and with the root file namespaced there, the arm case now fails in a root file as well: your forward_dotted_lib.bend on its own is refused on that branch (details on my comment on #1585). Your guard on top of it makes both files pass, so the patch is still needed. If I were you I’d open the PR against main now; if #1585 lands first, it’s a small rebase
Opened #1785 with the guard and the two tests from this thread, credited to @viridale there. Checked on main at 34003e6: the full test tree is unchanged apart from the two new files, and the repo gate passes.
Activity
viridale commentedon Oct 12, 2026
Confirmed on main at 0e14aa8. Your diagnosis is right, and the same double resolution breaks a second shape: a
\{..}arm that names a dotted constructor declared later.bend2/bend.tsis human-written (AGENTS.md), so here is a patch and a test for a maintainer to apply, not a PR.Cause
parse_varresolves a dotted name once and returns aRefthat holds the key (lib:Cell.At). Three call sites pass aRef's key toparse_resoagain:<..>branch, at bend.ts:2108;\{..}arm names, at L1842;(.. : T)operator namespace, at L2137.When the name is already in the book,
parse_resoreturns the key unchanged. For a forward name in an imported file,parse_qualadds the namespace a second time.A source name has no
:, sincechar_is_nameallows only letters, digits,_and.. So a key that contains:is already resolved, andparse_resocan return it unchanged:export function parse_reso(p: Parse, k: Name): Name { + if (k.includes(":")) { + return k; + } const dot = k.indexOf(".");Fixing only L2108 (
out.$ === "Ref" ? out.k : parse_reso(p, out.k)) clears the family head. The arm still fails:The patch also covers L2137. For a forward
T.addused in an imported file's(x + y : T), the import gave a different error (a defined name, observedops). It now gives the same error the entry file does: that the method is used before it is defined.Test
These go in
tests/import/. On main,forward_dotted.bendfails withunknown: forward_dotted_lib.forward_dotted_lib:Cell.At. With the patch it prints5.forward_dotted_lib.bend:forward_dotted.bend:With the patch, importing
tests/check/mutual_type_def.bendalso checks and prints6.What I ran
gates/test.ts's shard script, run locally on this Mac in 4 shards with the patch and the two tests, passes 1606 / 1608. The two failures aregfx_clicksandgfx_window. They expect "no display", but this Mac has a desktop session, so a window opens. main fails the same two here.Not run: the cluster gates, Linux and CUDA.
AbarnaaSree commentedon Oct 13, 2026
Hi @jasisz, I'd like to contribute to this issue. I reviewed the discussion and the proposed fix for the double resolution of imported forward dotted datatype names. Could you please assign this issue to me if it's still available? I'd like to work on the fix and add the necessary regression tests. Thank you!
HamedShams commentedon Oct 15, 2026
@viridale PRs that change
bend.tsare fine when a person writes them; the “do not edit it” line is inAGENTS.mdand is addressed to coding agents. Contributor commits to that file land regularly. Since the patch and both tests are already done, I suggest you open the PR yourself. It’s a cleaner credit trail than a maintainer lifting it from the thread.@AbarnaaSree this repo doesn’t hand out issues, so there’s no assignment to wait for. Those few assignees you’ve seen are the maintainers themselves. Whoever opens the PR has it! Since this one is already written up by @viridale, maybe it's better to proceed with another open issue.
HamedShams commentedon Oct 15, 2026
@viridale heads-up: #1585 fixes the
<..>head site but not the\{..}arm and with the root file namespaced there, the arm case now fails in a root file as well: yourforward_dotted_lib.bendon its own is refused on that branch (details on my comment on #1585). Your guard on top of it makes both files pass, so the patch is still needed. If I were you I’d open the PR against main now; if #1585 lands first, it’s a small rebaseHamedShams commentedon Oct 20, 2026
Opened #1785 with the guard and the two tests from this thread, credited to @viridale there. Checked on main at 34003e6: the full test tree is unchanged apart from the two new files, and the repo gate passes.