Repository navigation
fix: always emit a constructor for the entrypoint main object - #59
Merged
Merged
Conversation
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]>
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.
Symptom
A module created with
--entrypointand--template emptyloads without any error but never shows up indagger api functions. Adding an explicit emptyconstructor() {}to the class makes it appear.Root cause
The engine identifies an entrypoint module's main object by its constructor typedef alone (
isMainObject()incore/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 canonicaltinyexample follows that contract by always emitting.withConstructor(function("", ...)).The generator, however, only emitted
withConstructorwhen the class declared one. For a constructor-less main class the generatedtypes()registered a barewithObject(...), no object qualified as main, nothing was installed on the workspace root — and the module silently disappeared. The engine'svalidateEntrypointConstructorsrejects 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.
dangConstructorExpralready 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
TestGenerateDangEntrypointDefaultConstructorpins the emitted default constructor and that only the main object carries one (two constructors are an engine-side error).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-checkandinit template-checke2e 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.