Skip to content

fix: always emit a constructor for the entrypoint main object - #59

Merged
TomChv merged 1 commit into
mainfrom
fix/entrypoint-default-constructor
Sep 17, 2026
Merged

TomChv merged 1 commit into
mainfrom
fix/entrypoint-default-constructor

Conversation

@TomChv

@TomChv TomChv commented Sep 17, 2026

Copy link
Copy Markdown
Member

Symptom

A module created with --entrypoint and --template empty loads without any error but never shows up in dagger api functions. Adding an explicit empty constructor() {} to the class makes it appear.

Root cause

The engine identifies an entrypoint module's main object by its constructor typedef alone (isMainObject() in core/object.go, introduced with "Load modules through Dang entrypoints"): there is no name-based fallback, and the default constructor the engine synthesizes for [runtime] modules never happens on the entrypoint path. The canonical tiny example follows that contract by always emitting .withConstructor(function("", ...)).

The generator, however, only emitted withConstructor when the class declared one. For a constructor-less main class the generated types() registered a bare withObject(...), no object qualified as main, nothing was installed on the workspace root — and the module silently disappeared. The engine's validateEntrypointConstructors rejects more than one constructor but accepts zero, which is why nothing ever errored.

Fix

Emit the default no-arg constructor for the main object — matched by pascal-cased module name, mirroring the engine's rule for runtime modules — whenever the class does not declare one. dangConstructorExpr already renders the no-arg form for a nil constructor, and the generated dispatcher already handles the empty-name constructor call unconditionally, so the typedef half was the only piece missing.

Verification

  • New TestGenerateDangEntrypointDefaultConstructor pins the emitted default constructor and that only the main object carries one (two constructors are an engine-side error).
  • E2E against the manifest-v2 dev engine: regenerated the failing workspace with this branch; the module now lists in dagger api functions, and a method call on the constructor-less class dispatches through the synthesized constructor end to end.
  • generate entrypoint-installs-dependencies-check, generate generate-prunes-entrypoint-check and init template-check e2e checks pass.

Follow-up worth considering engine-side: have validateEntrypointConstructors (or the loader) warn or error when an entrypoint defines objects but no constructor, so a generator regression surfaces loudly instead of as an invisible module.

The engine identifies an entrypoint module's main object by its
constructor typedef alone: there is no name-based fallback, and the
default constructor the engine synthesizes for [runtime] modules never
happens on the entrypoint path. The generator only emitted
withConstructor when the class declared one, so a module whose main
class has no constructor — the empty template's, for one — registered a
bare object, was never installed on the workspace root, and silently
disappeared from `dagger api functions` while still loading cleanly.

Emit the default no-arg constructor for the main object (matched by
pascal-cased module name, mirroring the engine's rule for runtime
modules) whenever the class does not declare one. The dispatcher already
handles the empty-name constructor call unconditionally, so the typedef
half was the only piece missing.

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv
TomChv merged commit 86acd1c into main Sep 17, 2026
5 checks passed
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