Repository navigation
Version-gate reserved words; let modules shadow builtins - #212
Merged
Merged
Conversation
In a directory evaluated as a module (RunDir, DeclareDir, an imported Dang module), a top-level declaration named like a builtin or a prelude binding, e.g. `let loop = 1` or `pub toString(...)`, was silently dropped at evaluation, while the type checker used it: NewValueScope bound the builtins into the module's own frame, and FieldDecl.Eval does not publish a name its frame already binds (that check is for values a constructor provided). So `loop` stayed the builtin and calling the user's `loop(2)` failed with "too many positional arguments". Single-file RunFile was unaffected, since its file block evaluates in a derived scope. The builtins and prelude now live in a parent frame of the module's scope, so the module's own declarations shadow them like any outer binding, in every Dang version. Lookups and Bindings see the same names as before. Signed-off-by: Alex Suraci <[email protected]>
`rescue` was reserved in every version, though Dang 2.1 introduced it: `let rescue = 1` or `f(rescue: Int!)` stopped parsing in 1.0 and 2.0 modules, which have no postfix rescue. Reserved words now have a table, reservedWords, recording the version that reserved each, and a version-gated keyword's token only matches where it is reserved. That one gate covers both the word's exclusion from identifiers and the syntax built on it: before 2.1, `rescue` is an identifier and there is no postfix rescue, which also keeps `let y = foo` followed by a `rescue(1)` line meaning two forms, as it did. Before 2.1, try/catch is then the error handling syntax again: it no longer warns there (bare catch-alls included), and the formatter keeps it. From 2.1 on it still parses as a deprecated Legacy node, and the formatter rewrites it to the postfix form, so migrating to 2.1 rewrites try/catch. The rewrite is now an AST transformation, modernizeTryCatch, shared with the migration's meaning check, which compares a try/catch as its postfix equivalent. Signed-off-by: Alex Suraci <[email protected]>
Migrating to a version that reserves a word could not keep the names
spelled like it, public ones included (`pub rescue: Int!`), since renaming
changes what they mean. `$name` is now the identifier `name` in every
version, and the formatter writes it for an identifier the version it
formats reserves, so `dang migrate` escapes such names losslessly: only the
spelling differs, and `x.rescue` still selects the field `pub $rescue`
declares.
Where only a name can go, a reserved word is a name, so the escape is only
needed for declarations and bare references: after a dot (as before), in a
selection (`x.{{rescue}}`), as a named argument (`f(rescue: 1)`), and as an
object or object type key. null, a value, stays escaped there too.
TestReservedWords checks each reserved word in every version: where it is
an identifier, where it is a name, that `$word` always is one, and how the
formatter spells it. The tree-sitter grammar gains the escape and the
reserved names, hence its regeneration.
Signed-off-by: Alex Suraci <[email protected]>
Now that a module's own declarations shadow builtins, a Dang 1.0 or 2.0 module binding its own `loop` (legal there) would have its `for` loops call that `loop`, since they desugar to a call of the builtin by name. They now call it by an alias, `$loop`, which no identifier spells (`$loop` is the identifier `loop`), so nothing shadows it. It is left out of completions, and the formatter prints it as `loop`, as before. That spelling is the one place the shadowing still shows: migrating such a `for` loop writes a `loop` call, which the module's own `loop` would capture where it is in scope. Migration refuses that case, naming the line, rather than change what the loop does; scope is approximated by the enclosing blocks, functions, block params and clause bindings, plus the top level of the module's other files. Also pins that an unqualified import never shadows a builtin (qualified, it is still reachable). Signed-off-by: Alex Suraci <[email protected]>
Fixes from reviewing the branch:
- Before 2.1, `dang fmt` printed a `for` loop as a `loop` call, which a
module's own `loop` captures, so formatting broke a module that ran. `for
{}` and `for (cond) {}` now desugar to two aliases of the builtin, and
print back as the `for` loops they were wherever those exist; only
migrating to 2.1 writes `loop`, which forLoopCollision guards.
- forLoopCollision also checks constructor parameters.
- The formatter dropped the escape from `$true`, `$self`, `$break`, `$if`,
`$pub` and the like, whose bare spelling parses as something else where a
name can go; it keeps it now. TestKeywordNamesRoundTrip checks every
keyword's word as a declared and referenced name in every version.
- In a single-file run, an unqualified import could now shadow a builtin at
evaluation while inference kept the builtin; installing an import skips
builtin names explicitly, as the builtins no longer sit in the frame it
checks.
- The dang-language skill describes the versioned try/catch and `$rescue`.
Signed-off-by: Alex Suraci <[email protected]>
Fixes from a second review: - Before 2.1, try/catch is the version's own syntax, so it keeps its rules: a catch without clauses re-raises, and clauses after a catch-all are dead code rather than errors (the errors pointed at postfix rescue, which those versions can't parse). Migrating to 2.1 drops both. - Unqualified imports now skip builtin names in inference too, so a single-file run types such a name as the builtin it evaluates to. - The frame of builtins under a module's scope no longer counts as a generation of it: a method call on a module derived from it again instead of copying the whole module scope, as before builtins got their own frame. - forLoopCollision checks object literal fields, which are in scope for the fields after them. - The formatter keeps the escape on `$return`, `$raise` and `$else`, and the error docs describe the versioned try/catch. Signed-off-by: Alex Suraci <[email protected]>
Fixes from a third review. Migrating a 2.0 try/catch to postfix rescue could lose comments, or produce a file that no longer compiles: - A catch with clauses that can't match (after a catch-all, or repeating a type) stays a try/catch, which rescue would reject; one without clauses but with comments stays too. A try/catch keeps its own rules in 2.1, where it still runs with a warning, so the result compiles. - A try body with comments stays a block, and a commented catch-all stays a clause rather than becoming the fallback form; migration compares such a clause as the fallback form. - Comments before a catch's closing brace stay inside it. - The LSP's ranges for an escaped `$rescue` cover the name itself, so a rename keeps the escape. Signed-off-by: Alex Suraci <[email protected]>
vito
marked this pull request as ready for review
October 29, 2026 15:08
Deploying dang with
|
| Latest commit: |
8bec442
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f191c5f8.dang-3kk.pages.dev |
| Branch Preview URL: | https://versioned-language.dang-3kk.pages.dev |
The PR's patterns will recur, so give each a checklist: adding a keyword (reserved or not, incl. the TestKeywordNamesRoundTrip list, the feature method and tsPredicates), spelling names through Id/ReservedName and f.ident/f.fieldName, desugaring to builtins via $-aliases, per-version rules as AST flags, the builtins parent frame, and the unqualified-import hazard of new globals. Signed-off-by: Alex Suraci <[email protected]>
The authoring skill had picked up implementation details and change history with each incremental change: reserved-word escaping rules, legacy try/catch behaviour per version, dang.toml version parsing minutiae, Dagger prerelease handling, AST node names, prelude file paths. Cut those down to what an author needs, folded three copies of the equality rules into one, and fixed a comma-separated example that 2.1 rejects. Added the two author-facing points from this branch: `$name` names something like a keyword, and your own declarations shadow builtins while unqualified imports don't. Signed-off-by: Alex Suraci <[email protected]>
engineVersion is going away; dang.toml's `dagger` key is the source of truth for the Dagger API version. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Oct 29, 2026
Dang v2.3.0 (vito/dang#212) reserves `rescue` only from Dang 2.1 and lets a module's own declarations shadow builtins in every version, so a Dang 1.0 module that names something `rescue` or defines its own `loop` runs as it did on the Dang v1 line. That closes the two known gaps of Dang 1.0 mode; the README and changelog no longer list them. Its language versions are unchanged (CurrentVersion and DefaultVersion stay 2.1), and no engine call site changed. Unit and integration tests cover a Dang 1.0 module using both names. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Oct 29, 2026
Dang v2.3.0 (vito/dang#212) reserves `rescue` only from Dang 2.1 and lets a module's own declarations shadow builtins in every version, so a Dang 1.0 module that names something `rescue` or defines its own `loop` runs as it did on the Dang v1 line. That closes the two known gaps of Dang 1.0 mode; the README and changelog no longer list them. Its language versions are unchanged (CurrentVersion and DefaultVersion stay 2.1), and no engine call site changed. Unit and integration tests cover a Dang 1.0 module using both names. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 2, 2026
Dang v2.3.0 (vito/dang#212) reserves `rescue` only from Dang 2.1 and lets a module's own declarations shadow builtins in every version, so a Dang 1.0 module that names something `rescue` or defines its own `loop` runs as it did on the Dang v1 line. That closes the two known gaps of Dang 1.0 mode; the README and changelog no longer list them. Its language versions are unchanged (CurrentVersion and DefaultVersion stay 2.1), and no engine call site changed. Unit and integration tests cover a Dang 1.0 module using both names. Signed-off-by: Alex Suraci <[email protected]>
sipsma
added a commit
to grouville/dagger
that referenced
this pull request
Nov 3, 2026
Dang moves from the merge of vito/dang#205 to the merge of vito/dang#213, which adds ParseSourceFile. In between are the v2.2.0 and v2.3.0 releases and vito/dang#214, which change what Dang modules see: - The dang.toml that governs a module's source, found by walking up to the repository root, now sets the Dang version its source parses and evaluates as. A module with none keeps the newest version. A malformed dang.toml, which was ignored before, now fails the module's load. - A module's own top-level declarations shadow builtins of the same name (vito/dang#212). - JSON, YAML and TOML decode into Map[T] (vito/dang#214). - The Dang language skill the engine serves describes these. The engine still chooses a module's Dagger API version itself; the Dagger version a dang.toml can declare doesn't change it. Signed-off-by: Erik Sipsma <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 4, 2026
Dang v2.3.0 (vito/dang#212) reserves `rescue` only from Dang 2.1 and lets a module's own declarations shadow builtins in every version, so a Dang 1.0 module that names something `rescue` or defines its own `loop` runs as it did on the Dang v1 line. That closes the two known gaps of Dang 1.0 mode; the README and changelog no longer list them. Its language versions are unchanged (CurrentVersion and DefaultVersion stay 2.1), and no engine call site changed. Unit and integration tests cover a Dang 1.0 module using both names. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 4, 2026
Dang v2.3.0 (vito/dang#212) reserves `rescue` only from Dang 2.1 and lets a module's own declarations shadow builtins in every version, so a Dang 1.0 module that names something `rescue` or defines its own `loop` runs as it did on the Dang v1 line. That closes the two known gaps of Dang 1.0 mode; the README and changelog no longer list them. Its language versions are unchanged (CurrentVersion and DefaultVersion stay 2.1), and no engine call site changed. Unit and integration tests cover a Dang 1.0 module using both names. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 4, 2026
Dang v2.3.0 (vito/dang#212) reserves `rescue` only from Dang 2.1 and lets a module's own declarations shadow builtins in every version, so a Dang 1.0 module that names something `rescue` or defines its own `loop` runs as it did on the Dang v1 line. That closes the two known gaps of Dang 1.0 mode; the README and changelog no longer list them. Its language versions are unchanged (CurrentVersion and DefaultVersion stay 2.1), and no engine call site changed. Unit and integration tests cover a Dang 1.0 module using both names. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 5, 2026
Dang v2.3.0 (vito/dang#212) reserves `rescue` only from Dang 2.1 and lets a module's own declarations shadow builtins in every version, so a Dang 1.0 module that names something `rescue` or defines its own `loop` runs as it did on the Dang v1 line. That closes the two known gaps of Dang 1.0 mode; the README and changelog no longer list them. Its language versions are unchanged (CurrentVersion and DefaultVersion stay 2.1), and no engine call site changed. Unit and integration tests cover a Dang 1.0 module using both names. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 5, 2026
Dang v2.3.0 (vito/dang#212) reserves `rescue` only from Dang 2.1 and lets a module's own declarations shadow builtins in every version, so a Dang 1.0 module that names something `rescue` or defines its own `loop` runs as it did on the Dang v1 line. That closes the two known gaps of Dang 1.0 mode; the README and changelog no longer list them. Its language versions are unchanged (CurrentVersion and DefaultVersion stay 2.1), and no engine call site changed. Unit and integration tests cover a Dang 1.0 module using both names. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 5, 2026
Dang v2.3.0 (vito/dang#212) reserves `rescue` only from Dang 2.1 and lets a module's own declarations shadow builtins in every version, so a Dang 1.0 module that names something `rescue` or defines its own `loop` runs as it did on the Dang v1 line. That closes the two known gaps of Dang 1.0 mode; the README and changelog no longer list them. Its language versions are unchanged (CurrentVersion and DefaultVersion stay 2.1), and no engine call site changed. Unit and integration tests cover a Dang 1.0 module using both names. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 5, 2026
Dang v2.3.0 (vito/dang#212) reserves `rescue` only from Dang 2.1 and lets a module's own declarations shadow builtins in every version, so a Dang 1.0 module that names something `rescue` or defines its own `loop` runs as it did on the Dang v1 line. That closes the two known gaps of Dang 1.0 mode; the README and changelog no longer list them. Its language versions are unchanged (CurrentVersion and DefaultVersion stay 2.1), and no engine call site changed. Unit and integration tests cover a Dang 1.0 module using both names. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 5, 2026
Dang v2.3.0 (vito/dang#212) reserves `rescue` only from Dang 2.1 and lets a module's own declarations shadow builtins in every version, so a Dang 1.0 module that names something `rescue` or defines its own `loop` runs as it did on the Dang v1 line. That closes the two known gaps of Dang 1.0 mode; the README and changelog no longer list them. Its language versions are unchanged (CurrentVersion and DefaultVersion stay 2.1), and no engine call site changed. Unit and integration tests cover a Dang 1.0 module using both names. Signed-off-by: Alex Suraci <[email protected]>
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.
Dagger is deleting its separate vito/dang v1.0.1 library and running old modules on Dang v2 in
dang = "1.0"mode. A parity run found two places where 1.0 mode didn't behave like v1.0.1. This PR fixes both, and turns therescuecase into a general mechanism for version-gated keywords.1. Builtins were not shadowable, in any version
When a directory is evaluated as a module (
RunDir,DeclareDir, an imported Dang module), a top-level declaration named like a builtin or a prelude binding was silently dropped at evaluation. The type checker still used it:Cause.
NewValueScopebound the builtins into the module's own frame.FieldDecl.Evaldoesn't publish a name its frame already binds; that check exists for values a constructor provided. The same bug hit every builtin (let toString = ...too), and single-fileRunFilewas unaffected.Fix. The builtins and the prelude now live in a parent frame. Copy-on-write treats that frame as a root, so method calls on modules stay as cheap as before. Unqualified imports still never shadow builtins, in both inference and evaluation, for
RunDirandRunFile; the qualified name still reaches the import.2. Version-gated keywords: one grammar, version predicates
rescuewas reserved in every version, solet rescue = 1,pub rescue: Int!andf(rescue: Int!)failed in 1.0 mode. The design (agreed with vito) keeps one PEG grammar with version predicates, the mechanism the other version gates already use, rather than one.pegper version:reservedWords(version.go) records the version that reserved each word:null1.0,rescue2.1 (first tagged in v2.1.2).A gated keyword's token only matches where the word is reserved:
RescueToken <- "rescue" !WordChar RescueKeyword. That one gate covers both the word's exclusion from identifiers and the syntax built on it.let y = foofollowed by arescue(1)line would silently parse asfoo rescue (1).treesitter.goresolves the predicate for the current version, as it does for the other gates.Adding a keyword in a future version takes four edits:
reservedWords;!FooTokeninWordToken;ReservedName.TestReservedWordsthen covers the new word in every version. The language-versions skill documents this.try/catch before 2.1 is the error handling syntax again:
dang fmtkeeps it.dang fmtanddang migraterewrite it to postfix rescue throughmodernizeTryCatch.Raw identifier escape:
$name(please bikeshed)$nameis the identifiername, in every version, sodang migratecan keep names that a newer version reserves, public ones included:rescue.$is free in Dang's lexer outside${interpolations. Backticks are taken, and Rust'sr#rescuedoesn't work because#starts a comment.x.rescuex.{{rescue}}f(rescue: 1)nullis a value, so it stays escaped ($null) even in those name positions.3.
forloops can't be captured by a user'sloopBefore 2.1,
forloops desugar to aloopcall. Now that user bindings shadow builtins, a module defining its ownloopwould capture them.$forand$for(cond). No identifier can spell these, and they are left out of completions.forwhere the version has for-loops, and asloopin 2.1+.dang migraterefuses only a genuine collision (forLoopCollision): aforloop with a userloopin scope, including a top-levelloopin a sibling file of the same module.Tests
tests/builtin_shadowing_test.go:let, functions, sibling files, imported modules andDeclareDir, in 1.0, 2.0 and 2.1. Alsoforloops next to a userloop, and imports not shadowing builtins (RunDirandRunFile). The shadowing subtests fail without the fix.pkg/dang/version_test.go:TestVersionRescue: 1.0 and 2.0 acceptrescueas an identifier, try/catch formatting and migration.TestReservedWords: table-driven, every reserved word × every version.TestKeywordNamesRoundTrip: every keyword as a declared and referenced name, round-tripped through the formatter.try_catch.dangandrescue_identifier.dangunder2.0-to-2.1/.case_unmatched_raises.dangmoved to try/catch, since 2.0 never had postfix rescue.$rescueand reserved names, and an LSP range test.go test ./pkg/... ./cmd/... ./tests/passes. So do thetest/treesitter,fmt/staleandstalechecks forpkg/dangandtreesitter.Notes
$name, reserved names). Highlight queries live in theeditors/submodules and weren't touched.ValueScopeFromSchemabinds builtins over a schema's same-named root fields, inside the import's own scope.