Repository navigation
fix: refuse a module type named after a core type - #111
Merged
Merged
Conversation
TomChv
force-pushed
the
fix/union-alias-shadowing-core-type
branch
from
October 19, 2026 13:52
9a32fae to
a7eeb33
Compare
The engine namespaces a module's types against other modules, not against core, so a declaration sharing a core type's name does not get a namespace of its own: the core type answers for the name. Nothing failed. `type Volume = "loud" | "quiet"` generated a module taking a core Volume the author never mentioned — `dagger call ... --volume loud` then died on "unsupported volume address" — and `@object class Volume` generated an object whose own fields could not be queried. The union refusal added in #105 never fired for such a name, because the class lookup answered first. Go and Python modules collide with core the same way, so the scan refuses the declaration rather than working around it: a class, enum, interface or type alias named after a core class or enum is reported with its position and told to rename. It holds for the declaration, decorated or not and used by the module's API or not — an undecorated `class Volume` is the same silent failure one `@func` argument later, and a rule about a declaration does not depend on which of two declarations the resolver finds first. Referencing a core type is untouched — the rule is about a declaration in the module's own source, not a use of an imported `Container`. The core set is read from `client.gen.ts` alone, so a name shared with a dependency's client, which the engine does namespace, stays legal. Signed-off-by: Tom Chauveau <[email protected]>
TomChv
force-pushed
the
fix/union-alias-shadowing-core-type
branch
from
October 19, 2026 14:08
a7eeb33 to
e6f0597
Compare
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.
Problem
A type a module declares under a core type's name is silently taken to be that core type. No issue for this; the repro is below.
dagger generate -yexits 0 (== GENERATORS == ✔ 1 passed) and the recipe emits:So the module takes a core
Volume, which the author never mentioned, and the call fails on it:Passing something the core type does accept makes it unmistakable — the function is handed a core Volume object:
Controls on unmodified
main:Loudnessand fix: refuse a union type alias instead of registering it as a scalar #105's union check refuses it correctly:Unsupported union type alias 'Loudness' in src/index.ts. Declare an enum .... The name, not the shape, decided the outcome.export. Identical recipe ("no changes to apply"), identical failures.@object class Volumeinstead of an alias: generates fine, and the object is unqueryable —Cannot query field "level" on type "Volume".The same collision happens in the other SDKs, with a non-colliding control in the same module:
✔ .note: GoappNote!→fineCannot query field "level" on type "Volume"✔ .note: PyappNote!→fineCannot query field "peek" on type "Volume"✔ .loudness.level→loudCannot query field "level" on type "Volume"Namespacing exists so that two modules declaring the same type name do not collide with each other. It was never meant to isolate a module from core, and all three SDKs agree, so this is not an engine defect to work around — it is a declaration the SDK should refuse.
Root cause
library/src/module/introspector/dagger_module/module.ts:resolveReferenceslooks for aClassDeclarationby name first (:158), findsVolumein the module's own generatedclient.gen.ts, and because that file is a generated client registersObjectKindandcontinues (:163-169). #105's union check lives in the type-alias branch (:337), which a colliding name never reaches. A declared@object class Volumehas no reference to resolve at all: it is registered under its own name and the collision only shows up in the served schema.Fix
DaggerModule.validateNoCoreTypeShadowing(library/src/module/introspector/dagger_module/module.ts:392) refuses the declaration, before anything is resolved:Decisions worth calling out:
class Volumeis the same silent failure one@funcargument later, and a rule that holds for a declaration rather than for a use does not depend on which of two declarations the resolver finds first.client.gen.ts(AST.coreTypeNames,typescript_module/ast.ts:136). Scoped to that one file deliberately: a name shared with a dependency's client (<dep>.gen.ts) or with the module's own client is namespaced by the engine and stays legal. The file's type aliases are excluded too — the<X>Optsrecords exist only in TypeScript, to spell optional arguments, and have no schema type to collide with.findClasses. The error has to name the declaration the user wrote, and by the time a reference to it is resolved the core type has already answered for the name.@functaking or returning an importedContainer/Directory/Volumedeclares nothing and still resolves to the core object.AST.findResolvedNodeByName; with the refusal firing first that became dead weight and was dropped.Two paths fail open, both in the safe direction, neither worth code:
coreTypeNames()coming back empty makes the rule a no-op. That happens whenclient.gen.tsnever lands in the program — in the scan container an unresolved@dagger.io/*import does not fail, it degrades into a type that prints as the name that was written.clientwould emitclient.gen.tsand so be read as core, making its type names unshadowable.The introspector ships as a committed prebuilt bundle, so
library/bundle/introspector.jsis rebuilt here: 4,199,683 → 4,201,506 bytes (+1,823). It is the only bundle artifact that moved.Verification
Engine v1.0.0-beta.18 throughout (the floor v1.0.3 declares).
Reproduced on unmodified
mainfirst: every state above — exported, non-exported,@object class, and theLoudnesscontrol.Nothing in this repo trips the widened rule: cross-checking every class, enum, interface and type alias declared under
.dagger/,templates/and the introspector'stestdata/(117 declarations) against the 113 core class and enum names of beta.18 turns up exactly one collision,Volume, in the fixtures added here — plus #105's flatunionTypeAliasfixture, which has no generated client and so still takes the union path.With the fix, in the same throwaway workspace:
export type Volume = "loud" | "quiet"type alias Volume at src/index.ts:2:0 shadows the core Dagger type Volume. ...@object() export class Volumeclass Volume at src/index.ts:10:0 shadows the core Dagger type Volume. ...class Volume {}+@func shout(v: Volume), undecoratedclass Volume at src/index.ts:2:0 shadows the core Dagger type Volume. ...export type Loudness = "loud" | "quiet"export type Loudness = { level: string }+dagger call unionapp loudness levelloud— a non-colliding module type still works@func() echo(ctr: Container)+dagger call unionapp echo --ctr alpine:3.21hi— a real coreContainerargument, called for realNew coverage:
library/src/module/introspector/test/core_type_shadowing.spec.ts— a type alias, a decorated class and an undecorated class, each over a source directory of the newtestdata/shadowedCoreTypefixture (module source beside a generated client declaringclass Volume, modelled onsdkAlias). fix: refuse a union type alias instead of registering it as a scalar #105's fixture is flat, with no generated client, which is why it never caught this — and why it still exercises the plain union path. All three red without the fix:Error: scanning type alias Volume should have failed,scanning class Volume should have failed..dagger/modules/e2e—generate:generate-refuses-shadowed-core-type-check, overfixtures/shadowed-core-type/app. A scan failure reaches Dang asexit code: 1with stderr only in the trace, so this asserts the failure and the unit tests assert the message — the splitgenerate-refuses-duplicate-object-checkdocuments. Red without the fix (committed bundle swapped back tomain's):generating a module declaring a type named after a core type should fail, got: .../app/__dagger.entrypoint.ts, .../app/sdk/client.gen.ts, ...— i.e. generation succeeded.Checks run (e2e harness workspace, all green):
generate:generate-refuses-*(5, incl. the new one)generate:generate-checkpackager:library-tests(68 specs)packager:library-bundle/staleruntimes:*— the whole execution group, 12 checks, every fixture that declares helper classes and interfaces (interface-returns-checkpasses a coreContaineracross a module boundary for real)sdk:fixture-engine-version-check(new fixture added tomanagedTomlFixtures)Not covered
Platform,Bytes,JSON, the<T>IDaliases) are not in the refused set, because the set is the client's classes and enums. Left out on purpose rather than by oversight: a scalar is string-shaped on both sides, sotype Platform = stringresolving to the core scalar is near-harmless, unlike an object whose fields then cannot be queried.interface Envis refused too. Deliberate: it keeps the rule declaration-based, with no dependence on resolution order.engine-e-2-e:*.