Skip to content

fix(dang): resolve @cache args against file scope - #13455

Merged
vito merged 3 commits into
mainfrom
investigate-issue-13440
Jun 16, 2026
Merged

vito merged 3 commits into
mainfrom
investigate-issue-13440

Conversation

@vito

@vito vito commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Evaluate Dang @cache (and other) directive arguments against the owning type's captured closure — the file-local scope — instead of the top-level module scope, and bump vito/dang/v2 to the matching file-scope imports change so the two are consistent.

Why

In a multi-file Dang module, imports are file-scoped: they live in a per-file scope, not the aggregate module scope returned by RunDir. Directive arguments, however, were evaluated against that module scope after the fact, so a directive like:

withExec(args: [String!]!): Container! @cache(policy: FunctionCachePolicy.Never) { ... }

failed during module init whenever the declaring type lived in a file other than the first one processed:

failed to evaluate @cache argument policy: evaluating receiver: Symbol.Eval: "FunctionCachePolicy" not found in env: module {...}

Single-file modules only worked by accident — their imports leaked into the returned module scope.

How

Each Dang type's ConstructorFunction already captures the file-local scope it was declared in as Closure — the same scope rehydrated method bodies use at call time (callDangFunction). This change routes directive-argument evaluation through that closure, so imported symbols referenced by a directive resolve exactly as they do in the type's own source, regardless of how many files the module spans. Applies to both the v1 and v2 Dang SDK helpers.

Dependency bump

This also bumps vito/dang/v2 (v2.0.0 → pseudo-version at dang main, since the fix isn't in a tagged release yet). Only vito/dang/v2 is bumped; the frozen v1 lineage (modules with engineVersion < v0.21.5) keeps its pinned library, retaining only the harmless v1 helpers fix for multi-file v1 modules.

The bump spans v2.0.0, v2.0.1, v2.0.2, and post-v2.0.2 main. The PRs included:

The change this PR depends on

  • #135 — lang: file-scope imports in single-file modules. Imports are now file-scoped in single- and multi-file modules alike, instead of single-file modules leaking their imports into the returned module scope. Combined with the helpers change above, directive arguments referencing imported symbols resolve via the declaring file's closure in every case. Ships its own regression test (TestRunDirImportsFileLocalReachableViaClosure).

Language / parser changes (affect v2-lineage .dang authoring)

  • #130 — separate block statements with ; (a newline still works; only a stray comma between statements is now an error)
  • #132 — require braces on non-trivial if expressions
  • #119 — allow any expression as an if/else branch (drops ConditionalBody)
  • #124 — widen case branches; yield null when no branch matches
  • #108 — remove the for keyword in favor of a loop builtin; error on bare references to block-taking functions
  • #126 — allow constructors to define local variables

Formatting

  • #122 — better dot-block formatting
  • #127 — remove empty lines before braces

Docs, editor highlighting, and tree-sitter tooling (no language impact)

None of the repo's bundled .dang modules use the removed for keyword, and v2 semantics only apply to modules at engineVersion >= v0.21.5; older modules stay on the v1 lineage.

Tests

The unit-level regression test lives in vito/dang (TestRunDirImportsFileLocalReachableViaClosure, covering single- and multi-file modules). On the Dagger side, test-directives gains a withNeverCache function using @cache(policy: FunctionCachePolicy.Never) — a directive argument that references an imported symbol. Because the bump stops single-file modules from leaking imports, this case regresses without the helpers fix; verified failing pre-fix and passing post-fix against a dev engine.

Fixes #13440.

vito added 3 commits June 15, 2026 21:05
Directive arguments were evaluated against the top-level module scope,
which omits per-file imports in multi-file modules. A directive such as
@cache(policy: FunctionCachePolicy.Never) therefore failed to load with
"FunctionCachePolicy not found in env" whenever the declaring type lived
in a file other than the first one processed. Single-file modules only
appeared to work because their imports leak into the module scope.

Evaluate directive arguments against the owning type's captured closure
instead -- the same file-local scope that method bodies already use when
rehydrated at call time. Imported symbols referenced by directive
arguments now resolve exactly as they do in the type's own source,
regardless of how many files the module spans.

Fixes #13440.

Signed-off-by: Alex Suraci <[email protected]>
The companion fix in vito/dang makes imports consistently file-scoped:
single-file modules no longer leak their imports into the returned module
scope, matching how multi-file modules already behave. Combined with the
helpers.go change that evaluates directive arguments against the owning
type's captured closure, this means existing directive-using modules
(including single-file ones like .dagger/main.dang) now exercise the
closure path, so they regress if the fix is reverted. No separate Dagger
test is needed; vito/dang carries the unit-level regression test.

The fix is not yet in a tagged release, so this pins the pseudo-version
at dang main.

Signed-off-by: Alex Suraci <[email protected]>
Add a withNeverCache function to the test-directives module, annotated
with @cache(policy: FunctionCachePolicy.Never). The directive argument
references an imported symbol, so it resolves only if directive arguments
are evaluated against the declaring file's scope.

With the file-scope import bump in vito/dang, imports no longer leak into
the module scope even for single-file modules, so this regresses without
the helpers fix: the module fails to load with FunctionCachePolicy not
found. Verified failing pre-fix and passing post-fix against a dev engine.

Regression coverage for #13440.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito merged commit 7cc1842 into main Jun 16, 2026
79 checks passed
@vito
vito deleted the investigate-issue-13440 branch June 16, 2026 13:39
marcosnils pushed a commit that referenced this pull request Jun 16, 2026
* fix(dang): resolve @cache args against file scope

Directive arguments were evaluated against the top-level module scope,
which omits per-file imports in multi-file modules. A directive such as
@cache(policy: FunctionCachePolicy.Never) therefore failed to load with
"FunctionCachePolicy not found in env" whenever the declaring type lived
in a file other than the first one processed. Single-file modules only
appeared to work because their imports leak into the module scope.

Evaluate directive arguments against the owning type's captured closure
instead -- the same file-local scope that method bodies already use when
rehydrated at call time. Imported symbols referenced by directive
arguments now resolve exactly as they do in the type's own source,
regardless of how many files the module spans.

Fixes #13440.

Signed-off-by: Alex Suraci <[email protected]>

* go.mod: bump vito/dang/v2 to file-scope imports

The companion fix in vito/dang makes imports consistently file-scoped:
single-file modules no longer leak their imports into the returned module
scope, matching how multi-file modules already behave. Combined with the
helpers.go change that evaluates directive arguments against the owning
type's captured closure, this means existing directive-using modules
(including single-file ones like .dagger/main.dang) now exercise the
closure path, so they regress if the fix is reverted. No separate Dagger
test is needed; vito/dang carries the unit-level regression test.

The fix is not yet in a tagged release, so this pins the pseudo-version
at dang main.

Signed-off-by: Alex Suraci <[email protected]>

* core/integration: cover @cache directive arg resolution

Add a withNeverCache function to the test-directives module, annotated
with @cache(policy: FunctionCachePolicy.Never). The directive argument
references an imported symbol, so it resolves only if directive arguments
are evaluated against the declaring file's scope.

With the file-scope import bump in vito/dang, imports no longer leak into
the module scope even for single-file modules, so this regresses without
the helpers fix: the module fails to load with FunctionCachePolicy not
found. Verified failing pre-fix and passing post-fix against a dev engine.

Regression coverage for #13440.

Signed-off-by: Alex Suraci <[email protected]>

---------

Signed-off-by: Alex Suraci <[email protected]>
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
dagger 0.21.7

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## v0.21.7 - 2026-06-17

### Changed

- Bump default CNI IP address pool size to reduce address exhaustion under high container concurrency. by @sipsma in dagger/dagger#13394
- Bump Dang to v2.1.1, moving JSON encoding behind the `JSON` namespace (with a deprecated top-level `toJSON`) and picking up constructor scope and nullable input fixes. by @vito in dagger/dagger#13482

### Fixed

- `.env` file handling so non-matching variables are kept as hidden expansion context instead of being dropped, allowing later variables to expand against them. by @marcosnils in dagger/dagger#13490
- Filesync so syncing a re-included file under a gitignored directory (e.g. `foo/` ignored with `!foo/bar.txt`) no longer fails with `no such file or directory`; ignored parent dirs are now created on demand for visible descendants. by @grouville in dagger/dagger#13439
- A concurrent map panic during GC by guarding session client map iteration, preventing fatal `concurrent map iteration and map write` crashes. by @sipsma in dagger/dagger#13474
- Go SDK codegen so SDK auth config is forwarded to typedef generation, allowing modules with private transitive Go dependencies to resolve during codegen. by @grouville in dagger/dagger#13457
- Core enum handling to preserve conventional enum member names. by @shykes in dagger/dagger#13435
- The Apple `container` driver to honor the privileged option by granting all capabilities (`--cap-add ALL`), so the engine can bind-mount `/etc/resolv.conf` on startup with `container` 1.0.0's reduced default capability set. by @eunomie in dagger/dagger#13460
- Dang directive argument resolution so `@cache` (and other directive) arguments resolve against the declaring type's file scope, fixing `FunctionCachePolicy not found in env` errors in multi-file modules. by @vito in dagger/dagger#13455
- The report-mode heartbeat so it waits for its goroutine to exit before final render, avoiding interleaved output. by @kpenfound in dagger/dagger#13425
- Nullable result unwrapping for SDK input so nullable values are passed correctly into SDK functions. by @shykes in dagger/dagger#13401

### What to do next?

- Read the [documentation](https://docs.dagger.io)
- Join our [Discord server](https://discord.gg/dagger-io)
- Follow us on [Twitter](https://twitter.com/dagger_io)

</pre>
  <p>View the full release notes at <a href="https://github.com/dagger/dagger/releases/tag/v0.21.7">https://github.com/dagger/dagger/releases/tag/v0.21.7</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!11763
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.

Dang @cache directive cannot resolve FunctionCachePolicy enum in multi-file modules

2 participants