Skip to content

A dotted name an imported file resolved once is not resolved again - #1785

Closed
HamedShams wants to merge 1 commit into
bendlang:mainfrom
HamedShams:fix/forward-dotted-resolve
Closed

HamedShams wants to merge 1 commit into
bendlang:mainfrom
HamedShams:fix/forward-dotted-resolve

Conversation

@HamedShams

Copy link
Copy Markdown
Contributor

Closes #1514.

parse_var resolves a dotted name once and returns a Ref holding the key (lib:Cell.At). Three sites then pass that key to parse_reso again: the <..> family head, the \{..} arm names and the (.. : T) operator namespace. When the name is already in the book, parse_reso returns the key unchanged; for a datatype declared later in an imported file, parse_qual adds the namespace a second time and the term keeps lib:lib:Cell.At, a key no file declares. So a file that checks on its own fails as soon as it is imported.

A source name never contains : (char_is_name allows letters, digits, _ and .), so a key that has one is already resolved, and parse_reso now returns it as is. That covers all three sites in one place.

The guard and the two tests are @viridale's from the issue thread; I'm sending them as a PR since they'd been sitting there. Tests, in tests/import/: a module whose def names a dotted datatype and constructor declared below it, and an entry that imports it. On main the entry fails with unknown: forward_dotted_lib.forward_dotted_lib:Cell.At; here it prints 5, and the module alone still prints 7.

What I ran: every file under tests/ through bend <file> on main (34003e6) and on this branch, 1,688 shared outputs identical, the two new tests the only additions; bun gates/repo.ts 54/54. Not run: the cluster gates.

parse_var turns a dotted name into its key (lib:Cell.At) and returns a
Ref holding it. The <..> family head, the \{..} arm names and the
(.. : T) operator namespace passed that key to parse_reso a second
time; for a datatype declared later in an imported file, parse_qual
then prefixed the namespace again and the term kept lib:lib:Cell.At, a
key no file declares. A module that checked on its own failed the
moment it was imported.

A source name never contains ":", so parse_reso returns a key that has
one unchanged. Guard and tests from @viridale's analysis in the issue.

Closes bendlang#1514.
@HamedShams

Copy link
Copy Markdown
Contributor Author

@nicolas-abril a gentle ping on this one now that the queue has moved. I re-checked it today against main 4f99f4c1: it still merges cleanly, the import in forward_dotted.bend still fails there without the guard, and prints 5 with it. If #1585 is going to land first and cover this case, I'm glad to close this in its favour; otherwise happy to change whatever you'd like.

@Lorenzobattistela Lorenzobattistela self-assigned this Nov 3, 2026
@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Thanks for picking this up, and to @viridale for the analysis in #1514.

I'm closing this one. The guard fixes the symptom, not the cause. The <..>, \{..} and + sites take a key that parse_var already resolved and pass it to parse_reso again. The guard lets that through whenever the key happens to contain :. In the root file it is only correct because parse_qual does nothing there, so the double resolution is still in place, just no longer visible. We are stricter about changes to bend.ts, so we'd rather fix the callers so that a resolved Ref is never resolved a second time. #1514 also covers forms this PR leaves out: case Cell.Mk{v}: and +Cell.At<p> still fail when the type is declared later in the file. A fix for #1514 should handle those too. #1514 stays open for that.

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.

An imported forward dotted datatype is resolved as lib.lib:Type

2 participants