Repository navigation
Description
Summary
In a Dang module with multiple source files, using the core FunctionCachePolicy enum directly inside an @cache directive argument can fail during module initialization:
withExec(args: [String!]!): Container! @cache(policy: FunctionCachePolicy.Never) {
self.inner.withExec(args)
}
A top-level alias works around the problem:
let neverCache: FunctionCachePolicy! = FunctionCachePolicy.Never
withExec(args: [String!]!): Container! @cache(policy: neverCache) {
self.inner.withExec(args)
}
Expected behavior
@cache directive arguments should resolve core-prelude symbols the same way normal Dang source does, so FunctionCachePolicy.Never should be valid anywhere a FunctionCachePolicy directive argument is expected.
Actual behavior
The direct enum expression fails when evaluating the directive argument. The reported module also has a main.dang, and the failing directive is in another file.
Error excerpt:
Error: loading modules: loading extra module "k3s/tests": resolving module source "k3s/tests": failed to load dependencies as modules: failed to load module dependencies: failed to initialize module: init module: failed to create object Kubectl: failed to create method withExec for Kubectl: directives for withExec: failed to evaluate @cache argument policy: evaluating receiver: Symbol.Eval: "FunctionCachePolicy" not found in env: module {K3s: (name: String, nodePorts: [Int!], version: String, container: Dagger.Container): K3s!, Kubectl: (container: Dagger.Container!, service: Dagger.Service!, certs: Dagger.Directory!): Kubectl!, neverCache: Dagger.FunctionCachePolicy!}
The workaround works because neverCache becomes a module-level symbol visible in the directive-evaluation environment.
Reproduction sketch
Use a Dang module with more than one .dang file, including main.dang. In the non-first processed file, define a function with a cache directive that uses the enum directly:
type Kubectl {
withExec(args: [String!]!): Container! @cache(policy: FunctionCachePolicy.Never) {
dag.container().from("alpine")
}
}
Loading the module should fail with "FunctionCachePolicy" not found in env. Replacing the directive value with a top-level alias should allow module loading to continue.
Notes
The current implementation evaluates directive arguments as Dang expressions:
core/sdk/dang/v1/helpers.go:cacheDirectiveSelector->evalDirectiveArg->dang.EvalNode(ctx, env, node)core/sdk/dang/v2/helpers.go: same path
That means directive arguments depend on the specific ValueScope passed during module initialization. In this case, that scope appears to include module symbols but not the unqualified core-prelude enum symbol for files processed after the first one.
Activity
core/integration: cover @cache directive arg resolution
fix(dang): resolve @cache args against file scope (#13455)
fix(dang): resolve @cache args against file scope (#13455)