drop SubjectAs pointer-form fallback now that Parse returns values#18
Merged
Conversation
SubjectAs carried a reflection block that detected a pointer-form Subject (*subjectid.IssSubID), dereferenced it, and re-checked against the requested value type T. That existed to reconcile a split: before go-subjectid v0.2.0, Parse returned the pointer form while a Go-built SET held the value form, so the accessor had to absorb both. v0.2.0 removed the split — Parse now returns the value form, the same form a Go-built SET holds — so no supported flow ever places a pointer in SET.Subject. The reflection branch is dead for every supported input and is removed, along with the reflect import. SubjectAs is now nil guards plus a single value-form type assertion; IssSub is unchanged beyond the simplification it delegates to. The one observable consequence is for a SET hand-built with a *subjectid.IssSubID Subject: SubjectAs and IssSub now report ok=false for it rather than dereferencing it. No supported flow produces that shape — Parse yields a value, and a Go-built SET should hold a value — so consumers reading parsed subjects or building value-form SETs are unaffected. A typed-nil pointer Subject still returns ok=false without panicking: the value-form assertion fails without touching the pointee, which is what the old !rv.IsNil() guard protected against. TestSubjectAsPointerForm, which asserted the pointer form WAS read, becomes TestSubjectAsPointerFormUnmatched, asserting the hand-built pointer form now yields ok=false — pinning the value-only contract so a later reader doesn't mistake the removal for a regression. The doc comments on SubjectAs, IssSub, and SET.Subject drop their value/pointer framing, and encode_test.go's subject literal moves to the value form so the suite is uniformly value-form. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
Removes the reflection-based pointer-form fallback from
SubjectAs[T](and thereflectimport), makingSubjectAs/SET.IssSubmatch the value form of asub_idSubject Identifier only.Why
Before go-subjectid v0.2.0,
Parsereturned the pointer form while a Go-builtSETheld the value form, soSubjectAscarried a reflection branch to absorb both. v0.2.0 (#17) madeParsereturn the value form — the same shape a Go-built SET holds — so no supported flow ever places a pointer inSET.Subject. The reflection branch is dead for every supported input.SubjectAsis now nil guards + a singles.Subject.(T)value assertion.Behavior change
A
SEThand-built with a*subjectid.IssSubIDSubject now reportsok=falsefromSubjectAs/IssSubinstead of being dereferenced. No supported flow produces that shape (Parse yields a value; a Go-built SET should hold a value), so consumers reading parsed subjects or building value-form SETs are unaffected. A typed-nil pointer Subject still returnsok=falsewithout panicking — the value assertion fails without touching the pointee, which is what the old!rv.IsNil()guard protected.Changes
reflectimport; rewriteSubjectAs/IssSubgodoc to drop the value/pointer-absorption framing.SET.Subjectfield doc that described the pointer form as a possible held shape.ExampleSET_IssSub's value-or-pointer mention.TestSubjectAsPointerForm(asserted pointer form IS read) →TestSubjectAsPointerFormUnmatched(asserts hand-built pointer form yieldsok=false), pinning the value-only contract; the typed-nil subtest comment updated (no reflection path).[Unreleased]→Changedentry.Verification
Local CI mirror all green:
gofmt -l,go vet ./...,go mod tidy -diff,go test -race -shuffle=on ./...,golangci-lint v2.12.2 run ./...(0 issues). Code review clean.🤖 Generated with Claude Code