Skip to content

fix: refuse a union type alias instead of registering it as a scalar - #105

Merged
TomChv merged 1 commit into
mainfrom
fix-union-type-alias
Oct 14, 2026
Merged

TomChv merged 1 commit into
mainfrom
fix-union-type-alias

Conversation

@TomChv

@TomChv TomChv commented Oct 13, 2026

Copy link
Copy Markdown
Member

resolveTypeAlias treated a union like an intersection and registered it as a scalar named after the alias. Generation reported success; the failure landed somewhere else entirely.

type Volume = "loud" | "quiet"

@func()
shout(volume: Volume): string {
  return volume
}

What the user saw depended on whether the alias name collided with a core type:

typedef result
type Loudness = "loud" | "quiet" withScalar("Loudness") module fails to load: find mod type for function "shout" arg "volume" type: "Loudness!"
type Volume = "loud" | "quiet" withObject("Volume") the reference resolves against the generated client, so it becomes the core storage Volume, and --volume loud fails with unsupported 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} in client.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.Union in 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 boolean keeps working

boolean is true | false inside the compiler, so it reaches the same check. The ts.TypeFlags.Boolean branch above it is what keeps it a BooleanKind — ordering that nothing pinned before. The new scalarTypeAlias fixture covers it, alongside the intersection form.

The existing scalar fixture covers a core scalar imported from client.gen.ts, which takes the isGeneratedClientFile path instead, so neither shape was tested.

Tests

cd library && bun install && bun run --bun mocha
58 passing

Two new cases in type_alias.spec.ts: the union is refused with that message, and the intersection + boolean fixture still scans as ScalarKind + 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/stale catches it otherwise.

Full suite on beta.17, in a scratch workspace with .dagger/modules/engine-e2e/workspace.toml as dagger.toml:

dagger --x-release=v1.0.0-beta.17 check
== CHECKS ==  ✔ 93 passed

Not covered

  • A union of object types, or string | undefined. Both now raise, where before they produced a bogus scalar; neither is exercised by a fixture.
  • Whether a user-declared intersection scalar with a novel name can load at all. It scans as 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.

`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
TomChv merged commit 1a41e38 into main Oct 14, 2026
5 checks passed
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]>
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.

1 participant