Repository navigation
fix: refuse a union type alias instead of registering it as a scalar - #105
Merged
Merged
Conversation
`resolveTypeAlias` treated a union like an intersection and registered it as a scalar named after the alias: ```typescript type Volume = "loud" | "quiet" @func() shout(volume: Volume): string { ... } ``` Nothing defines such a scalar, and what the user saw depended on whether the name collided with a core type: - No collision: `withScalar("Loudness")`, and the module fails to load with `find mod type for function "shout" arg "volume" type: "Loudness!"`. - Collision: the reference resolves against the generated client instead, so `Volume` becomes the core storage type and the call fails with `unsupported volume address "loud": must use sshfs:// or engine-volume://` — an error about a value the function never took. Generation reported success either way. Only an intersection is a scalar, which is how every core scalar is declared (`type Platform = string & {__Platform: never}`). A union now fails generation with the alias, its file, and what to use instead. The message does not suggest the intersection form: that branch resolves by name, so it only works for a scalar the engine already knows. `boolean` is `true | false` inside the compiler and so reaches the same check — the boolean branch above it is what keeps it a BooleanKind, and the new fixture pins that along with the intersection form. Found while testing #86; unrelated to it, so it lands on its own. Signed-off-by: Tom Chauveau <[email protected]>
TomChv
added a commit
that referenced
this pull request
Oct 19, 2026
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 decorated class, an enum, an interface or a type alias named after a core class or enum is reported with its position and told to rename. 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
added a commit
that referenced
this pull request
Oct 19, 2026
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
added a commit
that referenced
this pull request
Oct 21, 2026
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]>
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.
resolveTypeAliastreated a union like an intersection and registered it as a scalar named after the alias. Generation reported success; the failure landed somewhere else entirely.What the user saw depended on whether the alias name collided with a core type:
type Loudness = "loud" | "quiet"withScalar("Loudness")find mod type for function "shout" arg "volume" type: "Loudness!"type Volume = "loud" | "quiet"withObject("Volume")--volume loudfails withunsupported volume address "loud": must use sshfs:// or engine-volume://The second is the bad one — an error about volume addresses for a function that never took a volume.
The fix
Only an intersection is a scalar. That is how every core scalar is declared (
type Platform = string & {__Platform: never}inclient.gen.ts), and the branch exists so one referenced in a signature resolves by name. A union has nothing to do with it, and the|| type.flags & ts.TypeFlags.Unionin that condition was doing all the damage.A union now fails generation, naming the alias, its file, and what to use instead. The message deliberately does not suggest the intersection form: that branch resolves by name, so it only works for a scalar the engine already knows — suggesting it would send people to a different load failure.
Why
booleankeeps workingbooleanistrue | falseinside the compiler, so it reaches the same check. Thets.TypeFlags.Booleanbranch above it is what keeps it aBooleanKind— ordering that nothing pinned before. The newscalarTypeAliasfixture covers it, alongside the intersection form.The existing
scalarfixture covers a core scalar imported fromclient.gen.ts, which takes theisGeneratedClientFilepath instead, so neither shape was tested.Tests
Two new cases in
type_alias.spec.ts: the union is refused with that message, and the intersection +booleanfixture still scans asScalarKind+BooleanKind. The other 56 pass unchanged, so no fixture in the repo was relying on a union alias.The introspector ships in
library/bundle/introspector.js, so that is rebuilt (4 lines) —packager:library-bundle/stalecatches it otherwise.Full suite on beta.17, in a scratch workspace with
.dagger/modules/engine-e2e/workspace.tomlasdagger.toml:Not covered
string | undefined. Both now raise, where before they produced a bogus scalar; neither is exercised by a fixture.ScalarKind, but the engine resolves scalars by name, so it almost certainly cannot — a separate question, and why the error message stays quiet about it.Found while building the repro for #86. Unrelated to that PR, so it lands on its own.