Repository navigation
fix(star): a sealed resource announces the methods it actually dispatches - #659
Merged
Merged
Conversation
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.
Phase 2 of #625. Closes #658.
Sealing a provider silently shrank its dispatchable surface. The generator derived a resource's method
metadata by inspecting the exported type; sealing moves the methods onto the unexported struct, where it
could not see them, so it emitted none:
Every stage downstream accepted that quietly —
nilmetadata is legal,parseParametersreturns an emptymap,
announcedMethodsmatches nothing. Forservice(#641) the three lost entries were framework-facing andnothing noticed. The next provider with an author-facing resource method would have lost it just as quietly,
with a green suite.
Why this is a fix and not a check
No build error is possible. An interface omitting a method its implementation has is well-formed Go. The
interface guard proves the struct satisfies the interface; the converse — that the interface exposes
everything worth dispatching — is not expressible as a type constraint.
An assertion at announce time was considered and rejected:
UnmarshalJSON,MarshalYAMLand friends areexported on the struct and legitimately do NOT belong on the interface, so "every exported method must be
declared" would fire falsely on every provider.
So the fix removes the failure instead of reporting it. The emitted metadata is plain strings and never
names a type — only the inspection target was the exported interface, and that was incidental. Inspecting the
implementation makes the metadata describe the struct dispatch actually reflects on, so the two cannot
disagree.
The detection needs no type query
Only an interface has zero receiver methods. So emptiness at the announced name is the signal, and the
implementation's name follows from ruling 3 — the interface takes the headline name, the struct its lowercase
form. A struct with no methods falls back to itself, which is correct either way.
Why before the provider sweep
Otherwise phases 3-6 each inherit the same silent risk and each need a manual "does this resource have
author-facing methods?" review — four chances to miss one, with no signal when you do. It also narrows phase 7
to asserting the shape rather than also policing dispatch.
Verification
service's three entries returned with no hand-editing of*.gen.go— the issue's exit criterion. Noother provider's announcement moved: the metadata shape of all twelve resource announcements is unchanged
(
file/gen/any_kind.gen.gostaysnil, the rest keep their 2 or 3 entries).make test103 ok ·make vetdarwin/linux/windows ·test-scenario·complexity·shell-lint·gofmt -l— clean. A second consecutive build runs zero codegen invocations, so the generator change didnot disturb the staleness property.
Also carried: the phase-1 finding that prompted this, and the plan's phases renumbered 1..8 with this inserted
as phase 2.